UITableView section header creeps under navigation bar
Asked Answered
S

4

7

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?

Spiv answered 3/12, 2012 at 9:26 Comment(0)
S
14

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.

Spiv answered 4/12, 2012 at 4:54 Comment(4)
Where is attribute inspector?Dugald
Content insets don't exist in the inspector, only scroll indicators insets.Enthrall
@SteveTaylor - check if you accidentally hid it using Hide button.Spiv
I checked again. It's not hidden. It's simply not there. Nevertheless, I resolved this problem not with magic numbers but instead by embedding my UITableViewController in a UINavigationViewController.Enthrall
S
8

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
Situla answered 15/4, 2014 at 20:55 Comment(1)
property pulltorefreshview not found on object of type tableviewPontic
C
1

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.

Centralism answered 5/1, 2014 at 12:0 Comment(1)
Tariq can you please share detail on this? After initial scrolling operation I can never get my first tableview element to be seen it creeps up under the navcontroller/bar. I see in the SVPullToRefresh code the originalTopInset var but it is used in many places - where should I change it and how?Florez
E
1

Easiest solution:

tableView.tableHeaderView = UIView()
Elect answered 16/3, 2021 at 3:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.