gpt4 book ai didi

iOS Present Viewcontroller 出现黑屏

转载 作者:可可西里 更新时间:2023-11-01 03:36:41 27 4
gpt4 key购买 nike

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

 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];

但是黑屏。可能是什么问题?

最佳答案

Alloc init AuthViewController 并不意味着将为 Controller 创建 View 布局。

这里的 View Controller 不加载它的 View ,这就是你得到黑屏的原因。使用 Storyboard对象和 View Controller 的标识符来加载其 View 。

AuthViewController Controller 的 Storyboard中指定 Storyboard标识符。

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

enter image description here

现在使用以下代码获取 AuthViewController Controller 对象:

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

关于iOS Present Viewcontroller 出现黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28022258/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com