UISearchDisplayController from the button, not the default search field

I was wondering if it is possible to activate the UISearchDisplayController using the button on the navigation bar, and not from the standard search bar that you get when you pull the search bar controller from the object library in Xcode. Like this feature in a calendar application:

UISearchDisplayController in the Calendar app You can get a button to trigger such an action:

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

But you still need a search bar, and it comes to life from where the search bar is. Ideally, I would like it to appear on top, like in a gif.

Any help is greatly appreciated. David.

+5
source share
1 answer

Old question, but I have an answer, so I thought it was worth revising ...

In the end, I used the UISearchController, not the UISearchDisplayController.

If you want to activate the search, but do not want the search bar, all you need to do is activate the search using

 self.searchController.active = YES; 

and then, because there is no search string, you need to implement the currentSearchController method: UISearchControllerDelegate methods.

 - (void)presentSearchController:(UISearchController *)searchController { [self.window.rootViewController presentViewController:self.searchController animated:YES completion:nil]; } 

It doesn't have the same animation at all, but I'm sure using the usual api view manager animation. I can get something like this.

+7
source

Source: https://habr.com/ru/post/1210277/


All Articles