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

我的未来我决定 提交于 2019-12-04 13:21:44

问题


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

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.

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


回答1:


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;



回答2:


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

Note: iOS 7 only



来源:https://stackoverflow.com/questions/23340275/add-a-uinavigationcontroller-nested-inside-a-container-view-controller-to-a-uita

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!