objective-c - 如何以编程方式将 seachDisplay Controller View 重置为原始状态

标签 objective-c uisearchdisplaycontroller uisearchbardelegate

我的 UISearchDisplayController 页面 View 如下(原始状态)

enter image description here

单击搜索栏并输入一些搜索词后,我会在表格中得到一个结果列表

enter image description here

点击表格中的一个条目后,一个新的viewController显示在栈顶

enter image description here

我的意图是在单击取消按钮(左上角)时, Root View 将显示 searchDisplay Controller 的原始状态

enter image description here

这是我试过的

在我的取消方法中(当我点击左上角的取消按钮时触发)

- (void)cancel
{
  [self dismissViewControllerAnimated:YES completion:NULL];
  [self searchBarCancelButtonClicked:self.searchDisplayController.searchBar];
}

在搜索栏委托(delegate)方法中我这样做了

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    self.searchBar.showsCancelButton = NO;

    [self.searchBar resignFirstResponder];
    self.searchBar.text = @"";
    searchDisplayController.searchResultsTableView.hidden = YES;
    [self searchDisplayControllerWillEndSearch:self.searchDisplayController];
}

点击取消按钮后我设法实现的是这个

enter image description here

原来的tableview好像不见了(点击页面才出现)

如何修改我的方法以将搜索恢复到其原始状态?

最佳答案

试试 [searchDisplayController setActive:NO animated:NO]

这应该隐藏搜索表。

关于objective-c - 如何以编程方式将 seachDisplay Controller View 重置为原始状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13985942/

相关文章:

ios - 使用 UISearchBar 后打开 detailViewController

ios - searchBarSearchButtonClicked 不能与 shouldChangeTextInRange 一起使用

iphone - 在 NSPredicate 更改后使用 NSFetchedResultsControllerDelegate 更新 TableView 部分和行

ios - 使用 xmpp 或任何其他框架在 ios 中使用 google 帐户构建聊天应用程序

ios - 是否可以使用 AVAudioEngine 播放 iOS 音乐库中的歌曲?

iphone - UISearchBar + didSelectRowAtIndexPath + cellForRowAtIndexPath

ios - UISearchDisplayController 重叠原始 TableView

ios - 在后台捕获图像?

iOS:使用 AFNetworking 解析 JSON 并检索特定信息?

ios - UISearchDisplayController 不完全覆盖 subview Controller