Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a UINavigationController nested inside a container view controller to a UITabBarController

I have a UIViewController (red) set as the first tab of a UITabBarController as shown in the storyboard below. This view controller is a container view controller and loads a UINavigationController inside its contentView (the white rectangle inside the red view controller).

Storyboard

This is my code for loading the navigation controller inside the red view controller's contentView:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // instantiate navigation controller
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UINavigationController *navigationVC = [storyboard instantiateViewControllerWithIdentifier:@"N"];

    // place navigation controller inside content view
    [self addChildViewController:navigationVC];
    navigationVC.view.frame = self.containerView.bounds;
    [self.containerView addSubview:navigationVC.view];
    [navigationVC didMoveToParentViewController:self];
}

From what I know about view controller containment this should work as I am explicitly setting the frame for the navigation controller. However, when there are enough cells in the tableView to exceed the container's height there is always a bar at the end of the tableView when I scroll down. I have set the tableView's backgroundColor to orange and the cell's backgroundColor to white in order to see the difference.

Gap at the end of the tableView

How do I get rid of that orange gap at the end of the tableView?

(Note: I am not using autolayout and I need a solution that works for both - iOS7 and iOS6.)

like image 546
Mischa Avatar asked Apr 28 '14 11:04

Mischa


1 Answers

I know you are also looking for an answer which works on iOS 6, but on iOS 7 and above you can use

self.extendedLayoutIncludesOpaqueBars = YES;
like image 154
kaischo Avatar answered Oct 11 '22 14:10

kaischo