popToRootViewControllerAnimated

popToRootViewControllerAnimated

我有两个视图,一个是根viewController,另一个是搜索viewController。当我在搜索viewController中的UISearchBar上单击“取消”时,我想重新选择到根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];在我的搜索视图的其他区域中起作用。

最佳答案

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

[self.searchDisplayController setActive:NO];

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

关于ios - searchBarCancelButtonClicked popToRootViewControllerAnimated,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17269635/

10-09 09:59