简体   繁体   中英

How do I close a UISearchDisplayController programmatically?

I want to close my UISearchDisplayController when the user clicks the "Search" button since I'm loading new data from the web. How do I close the controller programatically? I already have the proper method called, but don't know how to do it.

I thought that the below would work, but I'm wrong.

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

请享用。

You need to make sure you set active to false on main thread:

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

If you are using swift.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM