Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView section header creeps under navigation bar

Due to navigation bar style being translucent, I get my first section header (section # 0) hidden under my navigation bar.

I know this has been asked before, and a workaround to it is to do:

 self.navController.navigationBar.translucent = YES;

This places the problematic view correct - section header appears beneath the navigation bar instead of hiding behind it, which is what I want.

However, this invalidates my other view designs and leaves extra spaces in all of them, right under my nav bar.

How do I get the section header at correct place?

like image 237
Nirav Bhatt Avatar asked Dec 03 '12 09:12

Nirav Bhatt


3 Answers

Resolved:

  • Open storyboard file
  • select UITableView
  • Under attribute inspector -> Scroll view size -> Content insets, set Top = 44 (or whichever is your nav bar height).

See image below - it is under size section:

enter image description here

And here is how to fix it programmatically.

like image 54
Nirav Bhatt Avatar answered Nov 04 '22 02:11

Nirav Bhatt


To solve this while using SVPullToRefresh. I created the method below and inplace of [self.tableView.pullToRefreshView stopAnimating];

-(void)stopPullToRefreshAnimation
{
    [self.tableView.pullToRefreshView stopAnimating]; // call to stop animation

    UIEdgeInsets inset = UIEdgeInsetsMake(44, 0, 0, 0);
    self.tableView.contentInset = inset;
    self.tableView.scrollIndicatorInsets = inset;
} //stopPullToRefreshAnimation
like image 29
ShawnG Avatar answered Nov 04 '22 00:11

ShawnG


For others having this issue while using (SVPullToRefresh).

It can be solved by changing the view.originalTopInset in UIScrollView+SVPullToRefresh.m to whatever point you want your header to start at.

like image 1
Abuirshaid Avatar answered Nov 04 '22 00:11

Abuirshaid