gpt4 book ai didi

ios - 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因 : 'Application tried to present a nil modal view controller on target

转载 作者:行者123 更新时间:2023-11-29 04:31:18 25 4
gpt4 key购买 nike

我是 iPhone 新手,我试图在按下按钮时打开一个 View ,在我的“ReaderViewController”类中,我编写了以下代码:

- (void)tappedInToolbar:(ReaderMainToolbar *)toolbar emailButton:(UIButton *)button
{
#ifdef DEBUGX
NSLog(@"%s", __FUNCTION__);
#endif

#if (READER_ENABLE_MAIL == TRUE) // Option

instantiateViewControllerWithIdentifier:@"searchView"];

if (printInteraction != nil) [printInteraction dismissAnimated:NO]; // Dismiss

SearchViewController *searchController = [self.storyboard instantiateViewControllerWithIdentifier:@"searchView"];


searchController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
searchController.modalPresentationStyle = UIModalPresentationFullScreen;

[self presentModalViewController:searchController animated:YES];


[searchController release];


#endif // end of READER_ENABLE_MAIL Option
}

我想何时打开此 Controller “SearchViewController”的 View ,并且在 Storyboard 中我为 SearchViewController 的 View 提供了其标识符名称“searchView”但是当我运行时,它给了我以下异常:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:    'Application tried to present a nil modal view controller on target <ReaderViewController: 0x6864930>.'

有什么帮助吗?提前致谢。

最佳答案

Storyboard中没有标识符为 searchView 的 View Controller ,因此实例化失败并且

instantiateViewControllerWithIdentifier:

方法返回零。仔细检查您的 Storyboard 设置,并注意标识符和名称通常区分大小写,也许您将 View Controller 命名为 SearchView 而不是 searchView

也有可能是这样

self.storyboard

它本身没有正确初始化或实例化,因此为零。

编辑:所以您是从代码创建 Storyboard,但实际上不是。解决方案是手动实例化 UIStoryboard。

至于您自己的评论,您最好分配self.storyboard = Storyboard,否则您将继续收到这些错误...

关于ios - 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因 : 'Application tried to present a nil modal view controller on target,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11709844/

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