当我的应用程序在 iPad 上运行时,我想为我的 Root View 加载一个不同的 .xib。我已尝试按照您从下面的代码中看到的那样进行操作,但是发生的事情是线程进入正确的 if 语句,因此它识别它是 iPad,但是当加载 View 时,它会加载 iPhone 版本的 View 。
这是我的代码,我试图在应用程序委托(delegate)中决定为 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
这就是让您的结果变得困惑的原因。
关于ios - 如何为 iPad 加载不同的 Nib ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23878310/