UPDATE: Well, glad I spent the time preparing this…Apple decided to post it on their site…
- * *Happy iPad release day! Now that the iPad NDA has been been lifted, there are a lot of topics I’d like to write about. iPhone OS 3.2 brings about several new features including a new UIViewController called
UISplitViewController. This allows you to, in landscape orientation, have two UIViewContollers side-by-side. On device rotation to portrait orientation, the left-most UIViewController (the “rootViewController”) disappears from view and is replaced by a UIBarButtonItem in the right-most UIViewController (the “detailViewController”).
By default, you can only change the contents of the UIViewControllers in the UISplitViewController, but what if you want to swap in a completely different UIViewController to the detailViewController? There are countless iPad apps on the store right now that are doing this, from
Twitterific to Picture Sleuth (shameless plug). There must have been at least 8 different threads on the Apple Developer Forums about how to do this during the iPhone OS 3.2 NDA period, with Apple (mmalc) providing pretty good tips using Objective-C protocols. People still couldn’t follow it, so I implemented it and posted it to the Forum.
I’m sure other examples will be flooding the Internet soon, as I’ve seen some questions regarding my initial posted asked on Stack Overflow. Now that the NDA is lifted, you can download the example project (with few additional comments and clean-up).
You’ll mainly want to familiarize yourself with RootViewController.m’s UITableViewDelegate methods and the SubstitutableDetailViewController protocol. I’ve removed a lot of unused methods for readability, so you probably shouldn’t be using this as a starting template but rather a learning tool. We’re able to swap in multiple detailViewControllers by manipulating the viewControllers property of the UISplitViewController. This is more of a lesson in Objective-C protocols than anything, so if you’re in need of this code, you probably should be reading and understanding the Objective-C documentation on protocols from Apple first.
There are several other ways to do this (Picture Sleuth uses a different method) but it all boils down to the same stuff.