0

我是 iphone 新手,我试图在按下按钮时打开一个视图,在我的类“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
}

我想什么时候打开这个控制器“SearchViewController”的视图,在情节提要中我给 SearchViewController 的视图提供了它的标识符名称“searchView”,但是当我运行时,它给了我以下异常:

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

有什么帮助吗??先谢谢了。

4

2 回答 2

1

故事板中没有带有标识符的视图控制器searchView,因此实例化失败并且

instantiateViewControllerWithIdentifier:

方法返回零。仔细检查您的 Storyboard 设置,并注意标识符和名称通常区分大小写,也许您命名了视图控制器SearchView而不是searchView.

也可能是这样的

self.storyboard

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

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

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

于 2012-07-29T14:10:37.797 回答
0

在我看来self.storyboardnil。这意味着您传递给它的每条消息也会导致nil

于 2012-07-29T14:11:36.130 回答