OGeek|极客世界-中国程序员成长平台

标题: ios - 使用 Storyboard id iOS 以编程方式调用 View Controller [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:21
标题: ios - 使用 Storyboard id iOS 以编程方式调用 View Controller

我想要什么?

我的代码

但它崩溃了,我收到以下消息:

Terminating app due to uncaught exception 'NSInvalidARgumentException', reason: 'Application tried to present a nil modal view controller on target FutureOrderViewController: 0x199a4a30.



Best Answer-推荐答案


检查这些东西

检查 View Controller 的标识符,如果它与您在 Storyboard中提到的相同

enter image description here

确保您的 View 对象不为零。在该行和底部的调试区域设置断点,查看对象是否不为零。如果为 nil,则问题出在 Storyboard 连接上

如果您当前的 View Controller 不是从 Storyboard 启动的,则获取 Storyboard 对象,如下所示:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName"Main" bundle:nil];
UIViewController * feedbackVC = [storyboard   instantiateViewControllerWithIdentifier"FeedBackView"] ;
[self presentViewController:feedbackVC animated:YES completion:nil];

关于ios - 使用 Storyboard id iOS 以编程方式调用 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44022707/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4