Search code examples
iosobjective-csearchuisearchdisplaycontroller

Access Popover Controller on iPad UISearchDisplayController?


So I have a view with a UISearchDisplayController linked to a UISearchBar that is not contained within the navigation bar, but is positioned within the main view controller. It's all configured correctly to show a popover controller with results, however I need to obtain a reference to this popover controller.

Search Display Controller Popover

Firstly, I need to be able to style the navigation bar, as you can see in the above screenshot, it is not styled properly.

Secondly, I need to dismiss this popover when the user selects a result, the following code is not working:

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

I have even tried completely scrapping this popover and rolling my own, but I can't find a way to prevent this popover from being shown on the iPad. I need to use a UISearchDisplayController for the behavior on the iPhone, so i'd rather not get rid of it and roll my own search function entirely, has anyone got any ideas?


Solution

  • Resolved the problem I was having regarding the dismissal of the popover view. It turns out that the following lines do dismiss the popover controller...

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

    However, What I was doing immediately after that was populating the search string in the search field programatically (So the user retains a reference to what they actually searched for) In doing that, my search bar's delegate method performed another 'search' thus displaying the popover controller again...

    In the words of a famous cartoon character... Doh!