In a UISplitViewController
setup on iPad, RootViewController
is a UIViewController
class with a XIB file (not a UITableViewController
.)
My App has several targets. Depending on the target selected (and via #ifdef ...
in the code), I'd like to specify a different XIB file for RootViewController
.
I guess the changes have to be made in application:didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Add the split view controller's view to the window and display.
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
return YES;
}
== EDIT ==
I deleted all controllers from MainWindow.xib, then added the following lines in the AppDelegate. RootViewController is launched with the appropriate XIB, but the mechanics between RootVC and DetailsVC in SplitViewController does not work; ie. when hitting a button in RootVC that should trigger a change in DefaultVC, nothing happens. I am obviously missing something.
splitViewController = [[UISplitViewController alloc] init];
#ifdef OPTION1
rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController_1" bundle:nil];
#elif OPTION2
rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController_2" bundle:nil];
#endif
defaultViewController = [[[DefaultViewController alloc] init] autorelease];
UINavigationController *rootNav = [[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];
UINavigationController *defaultNav = [[[UINavigationController alloc] initWithRootViewController:defaultViewController] autorelease];
splitViewController.viewControllers = [NSArray arrayWithObjects:rootNav, defaultNav, nil];
splitViewController.delegate = defaultViewController;
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
// Add the split view controller's view to the window and display.
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
You code example seems like a really hard and confusing way to do a split view controller, so I'll just address the more general question:
My App has several targets. Depending on the target selected (and via #ifdef ... in the code), I'd like to specify a different XIB file for RootViewController.
If you have multiple targets defined in your project, you don't need #ifdef
s to do this. It's much simpler to use the target mechanism of the build process.
Lets say you have two resources, both called "MyFunResource", but one you'd like to use in a target called "blue", the other you'd like to use in one called "red".
Add both resources to your project. But in the file inspector (View > Utilities > Show File Inspector) note the section called "Target Membership". Note that all your targets are listed there with checkboxes next to them. When building a given target, a selected resource will only be copied into the bundle when it has that target's name checked here.
So select the "MyFunResource" that you want to be used in the "red" target, and makes sure "red" is the only thing with a checkmark next to it in "Target Memberships". Then select the one you want for "blue" and make sure only "blue" is checked.
Now when you build the red target, the build system will only copy the red-related resource into the bundle, so magically, the red resource is what will get used at runtime. And vice-versa with the blue. No code or '#ifdef's required.