当我的应用程序在iPad上运行时,我想为我的根视图加载不同的。xib。正如你从下面的代码中看到的那样,我尝试过这样做,但是发生的事情是线程进入了正确的if语句,所以它识别出它是一个iPad,但是当视图加载时,它加载了iPhone版本的视图。
这是我的代码,我试图在应用程序委托中决定为rootView加载哪个nib:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Add status bar
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.window.rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewControlleriPad" bundle:nil];
} else {
self.window.rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
}
self.window.rootViewController = self.navigationController; //Adds RootViewController to the NavigationController interface
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]}; // navigation titles
self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; // navigation buttons
您需要重做这一行:
self.window.rootViewController = self.navigationController; //Adds RootViewController to the NavigationController interface