ios - 如何为 iPad 加载不同的 Nib ?

标签 ios iphone objective-c ipad nib

当我的应用程序在 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/

相关文章:

iphone - 善用 XCode 性能工具

ios - 如何从一个 View 移动到另一个 View

ios - 如何将 textField 的 integerValue 放入数组中?

ios - 在 View 之间快速传递数据

ios - xcode 6 升级导致 prepare for segue lag showing screen

iphone - SpeakHere 示例无法播放从互联网加载的声音

ios - 如果数据源计数可能发生变化,是否可以同时使用 reloadItemsAtIndexPaths 和 reloadData?

ios - 推送时隐藏 Boom Bar 是导航栏错误的原因

ios - 如何平铺图像

objective-c - 如何在 Objective-C 中创建像 pinterest 或 piictu 这样的自定义标签栏