gpt4 book ai didi

ios - 如何控制 appdelegate 中的 View Controller ?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:00:54 24 4
gpt4 key购买 nike

我真的是为简单的问题构造结构。

我只是使用以下代码从一个 View Controller 移动到另一个 View Controller 。

homescreen *home;
home=[self.storyboard instantiateViewControllerWithIdentifier:@"home"];
[self presentViewController:home animated:YES completion:nil];

尝试在 AppDelegate 方法中使用相同的代码。

UIStoryboard *storyboard;
sur= [storyboard instantiateViewControllerWithIdentifier:@"survey"];
[self.window.rootViewController presentViewController:sur animated:YES completion:nil];

当我使用这段代码时,我遇到了崩溃:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target

我不想让它成为 Root View Controller ,只是我需要移动它。

最佳答案

您只声明了 UIStoryboard *storyboard 没有初始化它,并且在下一行中您在 nil 对象上调用方法 instantiateViewControllerWithIdentifier。最终 storyboard 变量替换了下一行中的 nil 并崩溃。

sur= [storyboard instantiateViewControllerWithIdentifier:@"survey"];

关于ios - 如何控制 appdelegate 中的 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34606580/

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