如何在设备类型上启动特定视图 [英] How to Launch Specific Views on Device Type

查看:104
本文介绍了如何在设备类型上启动特定视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在启动时启动3个视图中的1个。我想要启动的视图取决于设备类型。这是我到目前为止在 AppDelegate.m

I am trying to launch 1 of 3 views on startup. The view I want to launch is depending on the device type. Here is what I have so far in the AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568.0) {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_Portrait5" bundle:nil];
    }

    else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 480.0) {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_Portrait4" bundle:nil];
    }

    else {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_PortraitPad" bundle:nil];
    }
}

问题在于,当我启动应用时,有一个黑屏。

The problem is that, when I launch the app, there is a black screen.

推荐答案

你没有在窗口上设置控制器,在方法结束时添加:

You aren't setting the controller on the window, at the end of the method, add:

self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

这篇关于如何在设备类型上启动特定视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆