Raphael Caixeta
Raphael Caixeta

Reputation: 7846

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];
}

Upvotes: 30

Views: 7344

Answers (3)

xipengyang
xipengyang

Reputation: 96

func setActive(_ visible: Bool,
  animated animated;: Bool)

If you are using swift.

Upvotes: 2

LiorR
LiorR

Reputation: 31

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];
});

Upvotes: 3

Raphael Caixeta
Raphael Caixeta

Reputation: 7846

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

Enjoy.

Upvotes: 69

Related Questions