如何为iPad加载不同的笔尖?

时间:2014-05-26 22:07:11

标签: ios iphone objective-c ipad nib

当我的应用程序在iPad上运行时,我想为我的根视图加载不同的.xib。我已经尝试过,你可以从下面的代码中看到,但是会发生什么是线程进入正确的if语句,所以它确定它是一个iPad然而当视图加载时它加载了视图的iPhone版本

这是我的代码,我试图在app委托中决定为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

1 个答案:

答案 0 :(得分:2)

你需要重做这一行:

self.window.rootViewController = self.navigationController; //Adds RootViewController to the NavigationController interface

这就是你的结果。