UISplitViewController inside UITabBarController giving errors when it tries to check for [splitViewController viewControllers]

StackOverflow https://stackoverflow.com/questions/21138419

Question

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    UISplitViewController *splitViewController = (UISplitViewController *)[[tabBarController viewControllers] firstObject];
    UINavigationController *navigationController = [[splitViewController viewControllers] lastObject];
    splitViewController.delegate = (id)navigationController.topViewController;
}

This is my current code to check if the device is an iPad. If it is, it should set the tabbarcontroller's first object's last object's only view controller. The storyboard goes as following:

Tabbarcontroller[0]>Splitviewcontroller[1]>Navigationcontroller[0]>delegate(?)

I still have no idea what the delegate does, but upon checking apple's template code for a split view controller, I think it uses the delegate to notify the detail view controller to update content. The line I'm crashing is [splitViewController viewControllers]

Was it helpful?

Solution

According to Apple Guides UISplitViewController should be the root view controller i. e. it cannot be inserted into UITabBarController as child controller:

A split view controller must always be the root of any interface you create. In other words, you must always install the view from a UISplitViewController object as the root view of your application’s window.

From "View Controller Catalog for iOS" User Guide

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top