3

I have looked at the sample generated by xcode when creating a new UISplitView app on the iPad along with countless other tutorials and the documentation from the apple developer site. I have not seen an example where the UISplitView used was not the root of the application. Is this even possible?

What I am trying to accomplish: I have a UITableView to start out and once an item in the list is selected I would like to display a splitview with two different sets of information that is based on the item that was selected.

I curious if this type of implementation is even possible, or just frowned upon, and why. If it is possible, how would I go about implementing and hooking up a UISplitView to behave in this way?

Edit: I'm updating this with what I have. I can now switch to my UISplitView, though the transition is not animated. What is the way to correctly switch to a UISplitView so the transition is animated?

Code for switching right now:

[appDelegate.window addSubview:appDelegate.splitViewController.view];
appDelegate.window.rootViewController = appDelegate.splitViewController; 

EDIT 2: In hopes of bumping this back up so more people see it, I have managed to switch from my navigationController to my splitViewController, but when I add the button to be able to navigate back, nothing I do makes a difference and I seem to be locked in. I tried reverse mirroring the code to switch to the splitViewController, but that had no affect, and I am completely out of ideas. Can anyone shed some light on this?

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
Karoly S
  • 3,180
  • 4
  • 35
  • 55
  • 1
    UISplitViewController is a view controller like any other. So you can create one and use one at any time in your application. – onnoweb Aug 05 '11 at 17:20
  • That makes sense, which is why I was really surprised when I found no examples of it being integrated. I guess I don't really understand it SplitViews very well, could you give me a loose idea of how to implement this? I need my RootViewController and my DetailViewController for the two possible views, but those are just regular VC's. Where/how do I create my actual SplitViewController? – Karoly S Aug 05 '11 at 20:23
  • I changed your question title - I hope it better shows what you want. If it is wrong, feel free to revert. – Paŭlo Ebermann Aug 14 '11 at 17:35

3 Answers3

6

You should always use SplitViewController as a rootViewController: Split view controller must be root view controller

There may be some hacks around it, but when Apple have a strong recommendation and design guidance, I suggest to try to re-think your design before going against the platform -it should save you effort in the long term.

Community
  • 1
  • 1
Victor K.
  • 4,054
  • 3
  • 25
  • 38
3

I recommend using the MGSplitViewController, it also works as a non-rootViewController, even nested into an another MGSplitViewController, and there's i.e. a one-liner for the animation to blend in the Master-View, if that is what you want.

1

In your UITableView didSelectRowAtIndexPath method you would have something like:

UISplitViewController *mySplitView = [[UISplitViewController alloc] init];
[self.navigationController pushViewController:mySplitView animated:YES];
[mySplitView release];

Probably you'll want to subclass UISplitViewController just like you would other view controllers and set in there the master and detail views and so on.

onnoweb
  • 3,038
  • 22
  • 29
  • 2
    So I combined what you said with the answer from this question: http://stackoverflow.com/questions/2854840/how-do-i-create-a-uisplitview-manually. This seemed to compile, but when I try to actually select a row I get a "Split View Controllers cannot be pushed to a Navigation Controller" error. Any suggestions on how to work around this? – Karoly S Aug 08 '11 at 16:06
  • Alright, I changed the way my app was structured, and I have the functionality that I am looking for, though it doesn't behave in an ideal way, mainly, it doesnt animate. Is there any way to switch to a UISplitView and have the change animate? – Karoly S Aug 10 '11 at 15:15