重写RootViewController.xib在UISplitViewController
安装在iPad上,RootViewController
是UIViewController
类与XIB文件(不是UITableViewController
)在UISplitViewController
我的App有几个目标。根据所选的目标(并通过代码中的#ifdef ...
),我想为RootViewController
指定一个不同的XIB文件。
我想的变化具有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 ==
我删除从MainWindow.xib中所有控制器进行,然后加入在AppDelegate中以下行。 RootViewController与相应的XIB一起启动,但SplitViewController中的RootVC和DetailsVC之间的机制不起作用;即。当击中RootVC中的一个应该触发DefaultVC变化的按钮时,什么都不会发生。我明显错过了一些东西。
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];
谢谢杰姆斯,这绝对是比我想出来的更好的方式。 – 2012-07-01 14:32:53
我希望Apple会发布一些关于项目管理的好文档(甚至是WWDC视频!)。我每天都要通过试验和错误来发现太多东西 - 其中大部分都是在NeXTSTEP的旧版Project Builder中发现的! – jemmons 2012-07-01 14:37:52