views:

1792

answers:

1

I couldn't find a good answer anywhere to this. I am using a UINavigationController for my iPhone app, with everything is generated programmatically, nothing in Interface Builder. I am trying to port my app to iPad, using a UISplitViewController and my existing UINavigationController, but I am not sure where I should have the logic of my program separating the view controllers for iPhone or iPad.

Do I set up my main file to use a different app delegate or do I use the same app delegate and have the user interface conditionally set up within it?

Besides this, whenever I try to compile my app on the simulator it does not recognize the UISplitViewController or even the condition in which I check if the class exists.

Can please someone put me in the right direction, remembering that I am not using any xibs?

+3  A: 

If you want to see an example of a completely programmatic iPhone / iPad interface that uses a split view, you can download the source code of my application Molecules.

Within that application, I use one application delegate, but I set up the interface differently depending on which user interface idiom is present (iPad or iPhone). For the iPhone, I instantiate a root view controller which manages the appropriate interface for that device. For the iPad, I first create a UISplitViewController and attach it to the root window, then create my iPad-specific root view controller and place it as the detail view of the split view controller (with a navigation controller that I use for item selection as the left-hand controller for the split view).

Again, I recommend looking at that application project to see how I set this up programmatically. The code's available under a BSD license, so you can copy and paste this into your own application if you'd like.

As far as the compilation errors you're getting, you will need to migrate your application target to be a universal application using the "Upgrade Current Target for iPad" menu option. Once that has completed, set your build SDK to 3.2. Go to your application's build settings and set its Deployment Target to the earliest OS you want to support with your application (with 3.0 being the farthest back you can go).

Finally, you will need to weak-link UIKit. For how to do that, see my answer here.

Brad Larson
Thank you so much, molecules source code really helped me understand the whole thing. I am using the side view of split view for my table view that shares my existing table view oh the iphone app and the detail view of the splitview is now consists of two other views and are used to be accessible by navigationcontroller. btw, i love to see pi cubed on ipad.
arash13
I also used [[UIApplication sharedApplication].delegate performSelector:@selector(PushMyViewController)];to push a ViewController on my right view.. is it good or bad ? i am worried something horrible might happen later lol
arash13
Thanks for providing the Molecules source! When I build with Active SDK = Simulator 3.2, I can run the iPad simulator. But how can one test this app with simulator in iPhone mode? When I try setting Active SDK = Simulator 3.1.3, I get several compilation errors (e.g., can't find the UISplitViewControllerDelegate protocol declaration). What am I doing wrong? Thanks!
Clint Harris
@Clint Harris - Using the 3.2 SDK, there is no way to build to target the iPhone as a device in the Simulator with the source code as I have it configured. If you obtain the 4.0 SDK, you can set the base SDK to 4.0 (and clear out any references I have to the base SDK in the Target build settings) and be able to target either the iPhone or iPad in the Simulator.
Brad Larson