Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何以编程方式关闭UISearchDisplayController?_Iphone_Ios4_Uisearchdisplaycontroller - Fatal编程技术网

Iphone 如何以编程方式关闭UISearchDisplayController?

Iphone 如何以编程方式关闭UISearchDisplayController?,iphone,ios4,uisearchdisplaycontroller,Iphone,Ios4,Uisearchdisplaycontroller,我想在用户单击“搜索”按钮时关闭我的UISearchDisplayController,因为我正在从web加载新数据。如何以编程方式关闭控制器?我已经调用了正确的方法,但不知道如何执行 我以为下面的方法行得通,但我错了 - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { [self.searchDisplayController finalize]; } 享受。您需要确保在主线程上将active设置为false

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

我以为下面的方法行得通,但我错了

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

享受。

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

dispatch_async(dispatch_get_main_queue(), ^{
    [self.searchDisplayController setActive:NO animated:YES];
});

如果您使用的是swift。

非常感谢。。2012年的工作也很好,也很有帮助:)这对我不起作用。我说一旦用户点击-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(nsindepath*)indepath{[self.searchDisplayController setActive:NO-animated:YES];}中的某个位置,但这并没有让它消失。已调用此方法,但没有结果。完美。我在视图中使用此选项将消失。正是我所需要的。实际上,对于Swift来说,该属性是活动的
dispatch_async(dispatch_get_main_queue(), ^{
    [self.searchDisplayController setActive:NO animated:YES];
});
func setActive(_ visible: Bool,
  animated animated;: Bool)