Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISearchDisplayController from a button not the default search field

I was wondering if its possible to activate a UISearchDisplayController from a button in the navigation bar rather than from the standard search bar that you get when you pull out the Search Bar Controller from there object library in Xcode. Like this functionality in the calendar app:

UISearchDisplayController in the Calendar app You can get a button to fire an action like so:

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

But you still need the search bar and it animates from where the search bar is. Ideally I'd like it coming in from the top like in the gif.

Any help much appreciated. David.

like image 537
lateAtNight Avatar asked Jan 02 '15 18:01

lateAtNight


1 Answers

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

In the end I used UISearchController rather than UISearchDisplayController.

If you want to activate the search, but don't want a search bar, all you have to do it activate the search using

self.searchController.active = YES;

and then because there is no search bar you have to implement the presentSearchController: methods of UISearchControllerDelegate protocol yourself.

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

It doesn't quite have the same animation, but I'm sure using the usual view controller animation api I can get something similar working.

like image 72
lateAtNight Avatar answered Nov 02 '22 22:11

lateAtNight