gpt4 book ai didi

ios - 以编程方式呈现不同 Storyboard时出错

转载 作者:行者123 更新时间:2023-11-29 01:35:06 25 4
gpt4 key购买 nike

我有一个包含 2 个 Storyboard的应用。其中一个是主要的应用程序内容,另一个是用于设置用户配置文件的设置 Storyboard。现在,我已经设置好了,所以主界面是 Setup.storyboard .在该 Storyboard的第一个 View Controller 中,在 -viewWillAppear:animated 中方法,它检查 NSUserDefault查看设置是否完成。如果是,我执行这段代码。

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"userHasCompletedSetup"]) {

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
SWRevealViewController *vc = [sb instantiateViewControllerWithIdentifier:@"initialVC"];
[self presentViewController:vc animated:YES completion:NULL];
}
}

我收到错误 Warning: Attempt to present <SWRevealViewController: 0x7ff20a595220> on <MPOSetupOneViewController: 0x7ff20a720b80> whose view is not in the window hierarchy!

(我在我的应用程序中使用 SWRevealViewController 作为菜单。)

我得到这个错误, View Controller 没有切换。有什么办法可以根据 NSUserDefault 切换 Storyboard吗? ?我可以在 AppDelegate 中执行此操作吗?

最佳答案

只需将代码移至viewDidAppear:。在 viewWillAppear: 中,您的 View 尚未出现在界面中(这就是“will”的含义),因此没有任何内容可供呈现。

关于ios - 以编程方式呈现不同 Storyboard时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33049761/

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