40

I have a TabBarController, one of the tabs of which contains a sub view which is a navigationController. I am then loading into the navigation controller a view which inherits form UITableViewController.

My problem is thta for some reason the table view starts behing the navigation controller, not the top of the screen but about half way down the navigation bar, hence the top of the first cell in the table view is cut off.

Can anyone suggest how to move the UITableViewController down?

agough
  • 605
  • 1
  • 6
  • 7

3 Answers3

103

Fix it programmatically:

   - (void)viewDidLoad {
       UIEdgeInsets inset = UIEdgeInsetsMake(20, 0, 0, 0);
       self.tableView.contentInset = inset;
   }
sunkencity
  • 3,482
  • 1
  • 22
  • 19
  • 2
    This works great, but the scroll bars are a little messed up. They extend up under the nav bar here. It's like we need to change the frame instead of just adding an edgeInset to the scrollview. But that re-framing doesn't work – Chuck Pinkert Aug 02 '13 at 00:43
  • 4
    @chuckp16 You can also add `self.tableView.scrollIndicatorInsets = inset;` – dokkaebi Aug 10 '13 at 18:26
  • 4
    (64, 0, 0, 0) works the best for standard UINavigationBars (no prompt). – eulr Feb 17 '14 at 23:49
7

This "tucked in behind the Navigation bar" issue is due to iOS 7 using fullscreen layout automatically. See the iOS 7 Transition Guide.

It's a bit devious since it displays as in iOS 6 in the Simulator (layout-wise; ie. not tucked in behind).

Is your navigation bar translucent? Mine was, and setting it to non-translucent fixes it on Iphone iOS 6, iPhone iOS 7, and Simulator 7.0 building with XCode 5. (In my case I set it to translucent for visual appearance.)

Henrik Erlandsson
  • 3,797
  • 5
  • 43
  • 63
  • Hah! Just checked the dates... this wasn't about iOS 7 layout, was it? :) Gah. Well, I guess I could leave it in case this is the first hit people get searching for the issue nowadays, like I did. – Henrik Erlandsson Sep 27 '13 at 14:07
  • Even though this was not the case for the original question, this is a very helpful answer! – erdekhayser Dec 23 '14 at 02:58
-1

You can set the frame of the UITableView to an explicit X,Y position by setting the frame property on the view. Or you can change the same property using interface builder depending on whether you've added the tableview via IB or in code.

eg.

myTable.frame = CGRectMake(0.0, myTable.frame.origin.y + NAV_BAR_HEIGHT, myTable.frame.size.width, myTable.frame.size.height);

This will position the table myTable (which is a pointer to the UITableView) below the navigation bar, you may also need to adjust the height of the table accordingly. The height of the nav bar which I am indicating with a constant is 44.0.

I typically do this type of view adjustment if it has been necessary in the viewWillAppear of the view controller responsible. It's not common that you'll need to make this type of adjustment so it may be something you can fix by changing the way your views are being setup.

Without more details of how your view is setup it's hard to be more specific.

paulthenerd
  • 9,487
  • 2
  • 35
  • 29