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

↘锁芯ラ 提交于 2019-12-03 03:33:06

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

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

Can you add some more details on how you have wired up the UISearchDisplayController in IB? It does not do anything special with UIPopoverControllers on the iPad so I assume you have set the searchContentsController to a controller that is a UIPopoverController? If so then you already have the reference you need, though normally you do not need to dismiss this view, it is dismissed for you when you cancel the search.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!