30

我想在用户单击“搜索”按钮时关闭我的 UISearchDisplayController,因为我正在从网络加载新数据。如何以编程方式关闭控制器?我已经调用了正确的方法,但不知道该怎么做。

我认为下面会起作用,但我错了。

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    [self.searchDisplayController finalize];
}
4

3 回答 3

69
[self.searchDisplayController setActive:NO animated:YES];

享受。

于 2010-08-23T15:16:43.787 回答
3

您需要确保在主线程上将 active 设置为 false:

dispatch_async(dispatch_get_main_queue(), ^{
    [self.searchDisplayController setActive:NO animated:YES];
});
于 2014-01-02T08:56:54.437 回答
2
func setActive(_ visible: Bool,
  animated animated;: Bool)

如果你使用的是 swift。

于 2015-02-08T08:51:13.593 回答