Add a UINavigationController nested inside a container view controller to a UITabBarController
Asked Answered
W

2

6

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.)

Within answered 28/4, 2014 at 11:48 Comment(6)
set the tableView's background colour as nil, then wt's the problem with that .Allowed
The color of the tableView doesn't matter. It's the gap or the "extra row" that shouldn't be there.Within
I think that child VC (navigation controller) is respecting the parent tab bar.Candra
I agree. The question is: How do I make the table view controller understand that it should not respect the parent tab bar itself? Because obviously the navigation view controller adjusts its height with respect to the tab bar correctly and it's not the table view's job to do that...Within
Did you end up figuring this out?Gaudery
Did you figure that out? Maybe containerVC.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight; can work?Moltke
I
4

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;
Ingenerate answered 26/11, 2014 at 12:17 Comment(1)
It also can be defined on InterfaceBuilder on Attributes Inspector -> View Controller -> Extend Edges: Under Opaque barsAnimation
C
0

Have you tried setting self.edgesForExtendedLayout = UIRectEdgeAll; in -(void)viewDidLoad of Table View Controller - Root?

Note: iOS 7 only

Candra answered 28/4, 2014 at 11:52 Comment(1)
I need a solution that works for iOS 6 as well (updated my question). But I have also tried your suggestion and it did not work in iOS 7.Within

© 2022 - 2024 — McMap. All rights reserved.