Search code examples
iosxcodeuitableviewuisplitviewcontrolleruisplitviewdelegate

How do I implement a UISplitview in a UITabBarController with storyboards?


I have been searching high and low for an answer to this but none are for storyboards.

I have used this tutorial for creating my splitview and it works however the following part:

UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;

Won't work of course because the splitview is in a tabview.

How do I set my DetailViewController as the delegate?


Solution

  • The problem was because I was setting the SplitViewController as the root view in the delegate.

    I changed it to:

    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
        UISplitViewController *splitViewController = [tabBarController.viewControllers lastObject];//(UISplitViewController *)self.window.rootViewController;
        UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
        splitViewController.delegate = (id)navigationController.topViewController;
    

    And it works perfectly.

    It has also been approved by Apple.