0

What would cause the first row of a table in a nav controller to be positioned so part of it is under the nav controller?

I cannot seem to get it to show the whole row top to bottom; It may seem minor, but it's clearly not correct and I find it unattractive.

TableViewController added to nav controller entirely in code:

     SettingsRootController*settings=[[SettingsRootController alloc] initWithStyle:UITableViewStylePlain];
    self.settingsView=[[[UINavigationController alloc] initWithRootViewController:settings]autorelease];
    [settings release];

SettingsRootController is a subclass of UITableViewController.

What would cause the first row of a table in a nav controller to be positioned so part of it is under the nav controller?

johnbakers
  • 24,158
  • 24
  • 130
  • 258
  • We need to know (or see) how you created the tableview, otherwise we can only guess. XIB? Code? – sosborn May 24 '12 at 06:46
  • This has happened to me quite a few times. Please check the settings view frame size (or) set settings `frame` explicitly. – Legolas May 24 '12 at 07:00
  • Is the UINavigationController created in code too? Are you adding it as a subview somewhere? – Neo May 24 '12 at 07:05
  • Have you set the autoresizingMask for the tableView? – sosborn May 24 '12 at 07:13
  • i tried setting the autoresizing mask to None and it made no difference, so i'm not using that property at all. the nav controller is also created in code. i am setting the nav controller's frame explicitly; wouldn't this set the tableview to fit inside the nav controller? I tried giving the tableview an origin of (0,44) to accommodate the nav bar, but that had no effect – johnbakers May 24 '12 at 07:21
  • So, it is a UITableViewController in a UINavigationViewController? Why are you setting the frame for the nav controller explicitly? You don't want the tableview under the nav controller. It should be part of the nav controller You want the tableview under the navBar which is what should happen automatically. – sosborn May 24 '12 at 07:26
  • the tableviewcontroller is the rootcontroller of the nav controller, as my code shows. I position this nav controller where i want it on the screen; it is not to take up the whole screen, hence the explicit setting of the frame. you are correct that it should display correctly automatically, but it does not, as my screenshot above shows. – johnbakers May 24 '12 at 07:29
  • Then you have other things in your code that you are not showing us. Also, try setting the autoresizing mask of the tableview to UIViewAutoresizingFlexibleHeight. – sosborn May 24 '12 at 07:52
  • thanks for all these suggestions; it appears this is in fact an issue known to others, as the answer provided below suggests. i tried the tips here, no luck; i have no other code affecting these controllers that is worth showing. also I just discovered that the issue only appears on iPhone, not iPad. – johnbakers May 24 '12 at 08:05

2 Answers2

1

It seems that it is a common problem with programmatically-added UINavigationController - see Adding a UINavigationController as a subview of UIView.

Basically, what you should probably do is to set the frame property of UINavigationController before you add it as a subview to anywhere. In the accepted answer to the above question there's also a suggestion to alter the UINavigationController's frame to:

nav.view.frame = CGRectMake(nav.view.frame.origin.x, nav.view.frame.origin.y - 20,
                      nav.view.frame.size.width, nav.view.frame.size.height);
Community
  • 1
  • 1
Neo
  • 1,176
  • 2
  • 10
  • 15
  • hm, the issue described here is a bit different than mine. the nav controller displays in the right place for me; it's the table view that is not aligning correctly with the bottom of the nav bar – johnbakers May 24 '12 at 09:34
  • That's weird, I had the issue with navigation bar covering a bit of the first table cell and the proposed fix worked for me. However, the area covered was more like half a cell (~20px), not like yours (~10px). – Neo May 24 '12 at 10:38
1

the only thing that seems to work is manually shifting the table view inside the nav controller down by 10 pixels, but only on iPhone, not on iPad, since there is no alignment problem on iPad and shifting by 10 pixels on iPad creates a gap. this is clearly some sort of nav controller bug, as there are other weird issues noted in other threads.

 CGPoint tableorigin=CGPointMake(0,ISIPAD?0:10);
johnbakers
  • 24,158
  • 24
  • 130
  • 258