Help! My UITableView is the wrong size!

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;
}

Comments