Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISearchDisplayController automatically creates a UIPopovercontroller to display content search result ?! How to dismiss it?

I'm using a UISearchDisplayController with a UISearchBar. I put this UISearchBar in my app using IB and I get :

alt text http://img6.imageshack.us/img6/1985/screenshot20100701at156.png

Fine : when you start taping, the result popovercontroller appears magically (I didn't write anything on my own to make it appear !)

Then, when a row is clicked among the result, I want to dismiss the PopoverController BUT at this stage, I never instantiated the UIPopoverController on my side : it looks like if there's an encapsulated behavior in the UISearchDisplayController that automatically wraps its searchContentsController inside a UIPopoverController. That's really great because everything works perfectly without doing anything except that I cannot get the reference to this UIPopoverController to dismiss it :(

Does anyone know how to get the reference to this "magically" created UIPopoverController ? (this is the proof the iPad is really a "magical" device ;)

I thought there would be a reference to the UIPopoverController from its contentController (through its parent property for instance), but I cannot find any way to get a pointer to it :/

like image 222
yonel Avatar asked Jul 01 '10 12:07

yonel


2 Answers

Does [searchDisplayController setActive:NO animated:YES]; not work then?

like image 146
jrtc27 Avatar answered Jan 04 '23 06:01

jrtc27


None of above solutions worked for me, but I solved it with this:

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

This way cursor stays in the field but popover is dismissed when there are no results.

Full code:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    if ([searchText isEqualToString:@""]) {
        [self.searchDisplayController setActive:NO animated:YES];
        [searchBar becomeFirstResponder];
    }
}
like image 30
Rod Avatar answered Jan 04 '23 06:01

Rod