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

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

문제

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]

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top