27 Apr 2009

Is your UITableView too large for your UINavigationController? Is the content appearing behind your UITabBar? Then read on... :)

This one kicked my butt for a few hours today. I have my app structured using numerous XIB files and I have two possible root screens, one of which is the main one that loads in a UITabBarController which, in its first tab has a UIViewController with its own UIView which, in turn, has a UINavigationController whose view is a UITableView. The UINavigationController's view is added to the UIViewController's view as a subview. If you Google around, you'll find that when you start nesting these babies, you apparently start running into issues. Mine was that the UITableView was not displaying at the right height regardless of which component's settings I tweaked up the view hierarchy.

Very frustrating.

Of course, much Googling ensued and, finally, I stumbled upon this thread with the solution (a huge thank you to the poster nicknamed crinale). Note that I mentioned in the thread, I had to implement the fix in viewDidAppear: not in viewWillAppear::

 
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
 
	CGRect frame = self.view.frame;
	frame.size.height = 367;
	self.view.frame = frame;
}
 

Add Your Comment

Spam Protection by WP-SpamFree

Help! My UITableView is the wrong size!

  1. Reached much the same solution, though I didn’t hardcode the value: http://gist.github.com/330916

    Henrik N
  2. Your post really helped me. I am developing UINavigationController based app and after adding bottom toolbar UITableView did not show properly last element, so I was trying to change table’s height which turned out to be quite tricky. Now it’s done, thanks!

    reecon
  3. This works wonders! Except for one thing… after displaying a modal view controller all my view controllers in the navigation controller go back to the wrong size and are overlapped by the tab bar controller. :(

    Accatyyc
  4. Great tip! Thanks. There are a lot of complicated solutions to this problem out there but this is the quick and clean one I was hoping to find. Thanks again.

    Bob Sellon
  5. Thanks. I search for that for a while. I also tried everything under the sun.

    Terry
  6. Thank you so much for this! I’ve been working on this little problem for quite some time now!

    Tim Walsh
  7. Thank’s a lot.
    A very simple solution which work well for me.

    omnia69