iOS Present ViewController 黑屏 [英] iOS Present Viewcontroller getting black screen
问题描述
我正在尝试使用 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屋!