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

后端 未结 3 812
面向向阳花
面向向阳花 2021-02-06 11:03

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/screenshot2

3条回答
  •  旧时难觅i
    2021-02-06 12:06

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

提交回复
热议问题