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

1k Views Asked by At

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?

2

There are 2 best solutions below

0
Leon On BEST ANSWER

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.

7
rdelmar On

You don't. Split views have to be the root view controller of the window. You can't have one embedded in a tab view controller.