Add a UINavigationController nested inside a conta

2019-03-21 01:27发布

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

2条回答
男人必须洒脱
2楼-- · 2019-03-21 02:04

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;
查看更多
来,给爷笑一个
3楼-- · 2019-03-21 02:12

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

Note: iOS 7 only

查看更多
登录 后发表回答