开发者社区> 问答> 正文

如何根据设备类型启动特定的视图

在启动时候有三个视图,想要实现的是可以根据设备类型来选择三个中的一个。目前我写的代码在AppDelegate.m中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // 应用启动后重写制定
    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];
    }
}

但是运行之后,应用启动的时候屏幕一片漆黑。

展开
收起
爵霸 2016-05-27 10:33:03 1632 0
1 条回答
写回答
取消 提交回答
  • 在方法的最后添加:

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    2019-07-17 19:17:14
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
动态、高效,蚂蚁动态卡片的内核逻辑 立即下载
内容驱动游戏分发 立即下载
低代码开发师(初级)实战教程 立即下载