iOS Present ViewController 黑屏 [英] iOS Present Viewcontroller getting black screen

查看:41
本文介绍了iOS Present ViewController 黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 StoryBoards 创建的当前 ViewController:

I am trying present ViewController I have created with StoryBoards:

 AuthViewController *authViewController = [[AuthViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:authViewController];
    UIViewController *vc  = [[[[UIApplication sharedApplication] windows] firstObject] rootViewController];
    [vc presentViewController:nav animated:YES completion:nil];

但是在黑屏时得到它.可能是什么问题?

But getting it with black screen. What could be the issue?

推荐答案

Alloc init AuthViewController 并不意味着会为控制器创建视图布局.

Alloc init AuthViewController does not mean that will create a view layout for controller.

这里视图控制器没有加载它的视图,这就是为什么你会黑屏.使用故事板对象和视图控制器的标识符来加载其视图.

Here view controller does not load its view that's why you are getting black screen. Use storyboard object and identifier of view controller to load its view.

AuthViewController控制器的Storyboard中指定storyboard标识符.

Specify storyboard identifier in Storyboard of AuthViewController controller.

添加Storyboard ID并为Use Storyboard ID选项标记true,如下图:

Add Storyboard ID and mark true for Use Storyboard ID option like in below image:

现在使用以下代码获取 AuthViewController 控制器对象:

Now get AuthViewController controller object using below code:

AuthViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"AuthViewController"];

这篇关于iOS Present ViewController 黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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