Search code examples
iosautolayoutuinavigationbaruisplitviewcontrolleruicontainerview

Content falls beneath navigation bar when embedded in custom container view controller and UISplitViewController


I am using UISplitViewController and UIContainerView as shown in fig.

enter image description here

Code for displaying this is:

self.slidingViewController.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SplitContainerVC"];

It am Pretty sure auto layouts for container view are accurate.

Why my content view (search bar etc) is beneath UINavigation bar? Please see attached fig.

enter image description here

I have removed following code and its work fine:

- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
    return NO;
}

But i need this above code. What's an issue behind this?


Solution

  • Starting in iOS 8 you should use preferredDisplayMode. As shouldHideViewController is deprecated in iOS8.

    To show both view controllers in portrait mode do the following:

    self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
    

    Hope this helps!