Question

In previous versions of Xcode creating a window-based, universal application would populate the project with iPhone and iPad specific files and assign the appropriate entry points. All that was required was modifications to the iPhone/iPad controllers/xibs to create device specific interfaces.

Sadly, XCode 4.3 no longer offers a window-based template (empty application is the closest) and I don't know how to appropriately configure the entry points. This is fairly strait forward using storyboarding, but I would like to do it using programmatic or xib-based work flows.

I have created two view controllers and xibs: HomeViewController_iPhone and HomeViewController_iPad. Simply setting the entry point for each device to the appropriate HomeViewController crashes the app. I suspect I need to do a bit more to subclass the application delegate, but I'm not quite sure how to proceed. Any pointers?

Was it helpful?

Solution

This is something like what I do when using a navigation controller aswell. Depending on the device the code loads the correct xib. This goes in didFinishLaunchingWithOptions in the AppDelegate.m. navigationController is a property in AppDelegate.h

UIViewController *rootViewController;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    rootViewController = [[HomeViewController_iPhone alloc] initWithNibName:@"HomeViewController_iPhone" bundle:nil];
}
else {
    rootViewController = [[HomeViewController_iPad alloc] initWithNibName:@"HomeViewController_iPad" bundle:nil];
}

navigationController = [[UINavigationController alloc]
                 initWithRootViewController:rootViewController];

self.window = [[UIWindow alloc] 
               initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;

Hope it helps towards a solution!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top