1

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?

Leon
  • 3,614
  • 1
  • 33
  • 46

2 Answers2

3

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.

Leon
  • 3,614
  • 1
  • 33
  • 46
0

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.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • I have found plenty of threads where it's been done and accepted by Apple. The Amazon app is an example. – Leon Jan 09 '13 at 09:49
  • You will have to implement a custom view controller. But you can find plenty open source ones on the internet. rdelmar is right in that split views (the ones provided by apple) must be the root view controller – Siddharth Dhingra Jan 10 '13 at 21:26
  • @leon, according to Apple's own documentation, it's not possible. Are you sure these threads are using actual UISplitViewControllers, and not just something that looks like one? – rdelmar Jan 10 '13 at 21:28
  • It's definitely possible, as I said the Amazon app does it for a start. Also here a look at the first few hits here: [Google Search Results](https://www.google.co.uk/search?q=uisplitviewcontroller+inside+tabbarcontroller) – Leon Jan 11 '13 at 13:17
  • @Leon, If you've found all these results, then go to it. Why are you asking the question? – rdelmar Jan 11 '13 at 15:55
  • Because they all work for pre-storyboards, hence the question. – Leon Jan 11 '13 at 18:15
  • It might get you in trouble, but you can do it just like anything else in the storyboard. Start with the tabbed application template, delete one of the 2 controllers it gives you, drag out a split view controller, and control-drag from the tab bar controller to the split view controller. This appears to work, but whether it has hidden problems, or whether Apple would approve of a product like this, I don't know. – rdelmar Jan 11 '13 at 20:28