Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two UISplitViewControllers, 1 (Shared) Detail View

To set the scene I have:

  • A Tab View Controller with 2 tabs
  • Each tab has a Split View Controller
  • I'd like to point the Detail view of each Split View Controller to the SAME view.

I've attached a very simple sample project showing the issue.

Run it in the iPad 5.1 Sim, observe each tab. One shows the shared detail view, one fails.

NSLog debugging reports that the second split view has a NULL detail view controller:

2012-04-28 07:21:55.451 svcTest[14597:f803] tabBarController viewControllers = (
    "UISplitViewController: 0x6a36100",
    "UISplitViewController: 0x6a39ab0"
)
2012-04-28 07:21:55.455 svcTest[14597:f803] svcA.viewControllers = (
    "UINavigationController: 0x6a36250",
    "UIViewController: 0x6a38720"
)
2012-04-28 07:21:55.457 svcTest[14597:f803] svcB.viewControllers = (
    "UINavigationController: 0x6a39cc0"
)

When you click the second tab you get this error:

2012-04-28 07:22:58.457 svcTest[14597:f803] Splitview controller  is expected to have a detail children before its used!
2012-04-28 07:22:58.459 svcTest[14597:f803] Split view controller  should have its children set before layout!

Looking at the storyboard I have already set the detail views so this really confuses me.

Storyboard

Any help getting this 'shared' view to show up on each tab is much appreciated.

Thanks!

like image 237
Timbo Avatar asked Nov 04 '22 01:11

Timbo


2 Answers

I received the same warning when specifying more than two viewControllers for the splitViewController as shown below:

self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController, subViewController];

When i removed 'subViewController' from the array the warning disappeared.

After reading apple's documentation on adding / removing subviews it mentions the following:

The array in this property must contain exactly two view controllers. The view controllers are presented left-to-right in the split view interface when it is in a landscape orientation. Thus, the view controller at index 0 is displayed on the left side and the view controller at index 1 is displayed on the right side of the interface.

You can check out the link to UISplitViewController Class Reference for more information.

like image 90
user1607261 Avatar answered Nov 15 '22 05:11

user1607261


The Problem is in placement of some lines located in App Delegate's -applicationdidFinishLaunchingWithOptions:

Here, the split view controller delegate is set before the viewControllers. This seems to be the source of the problem and if you reverse the two lines as shown below the warning message disappears:

Use this Code instead :

self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.viewControllers = [NSArray
                           arrayWithObjects:masterNavigationController,
                           detailNavigationController, nil];
self.splitViewController.delegate = detailViewController;

For detailed explanation, you can take a look at : Splitview Controller Is Expected to Have a Master View Controller

like image 39
Bhavin Avatar answered Nov 15 '22 07:11

Bhavin