searchBarCancelButtonClicked popToRootViewControllerAnimated

时间:2013-06-24 06:57:07

标签: ios objective-c cocoa-touch

我有两个视图,一个是根viewController,另一个是搜索viewController。当我在搜索viewController中单击UISearchBar上的cancel时,我想要回到根viewController。我有这段代码:

-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    [self.navigationController popToRootViewControllerAnimated:YES];
    }

但是当我点击取消时,我收到了这个错误:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'search contents navigation controller must not change between -setActive:YES and -setActive:NO'

我做错了什么? [self.navigationController popToRootViewControllerAnimated:YES];适用于我的搜索视图的其他区域。

1 个答案:

答案 0 :(得分:7)

在弹出导航控制器之前,您需要先隐藏搜索显示控制器:

[self.searchDisplayController setActive:NO];

这将隐藏没有动画的搜索界面。