几个月前,我曾要求question展示UISearchDisplayController,它就像魅力一样,但是
现在我在用户点击 searchResultsController的 tableview单元格后呈现另一个控制器,它选择一个单元格并隐藏 searchResultsController 以显示MapView但是一旦点击搜索栏 searchResultsController 没有显示,但是一旦按下取消按钮并再次点击搜索栏,它就会重新开始工作。
情景正是Apple的地图应用程序打开了最喜欢的视图以及带有细分的最近视图控制器。
这是我的UISearchControllerDelegate代码:
- (void)willPresentSearchController:(UISearchController *)searchController
{
mainViewController *__weak weakSelf=self;
dispatch_async(dispatch_get_main_queue(), ^{
mainViewController *__strong strongSelf = weakSelf;
strongSelf.searchController.searchResultsController.view.hidden = NO;
});
}
- (void)didPresentSearchController:(UISearchController *)searchController
{
self.searchController.searchResultsController.view.hidden = NO;
}
这是我的UISearchBarDelegate代码。
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
mainViewController *__weak weakSelf=self;
dispatch_async(dispatch_get_main_queue(), ^{
mainViewController *__strong strongSelf = weakSelf;
strongSelf.searchController.searchBar.showsCancelButton = YES;
});
self.searchController.searchResultsController.view.hidden = NO;
return YES;
}
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar{
mainViewController *__weak weakSelf=self;
dispatch_async(dispatch_get_main_queue(), ^{
mainViewController *__strong strongSelf = weakSelf;
strongSelf.searchController.searchBar.showsCancelButton = NO;
});
return YES;
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
mainViewController *__weak weakSelf=self;
dispatch_async(dispatch_get_main_queue(), ^{
mainViewController *__strong strongSelf = weakSelf;
strongSelf.searchController.searchResultsController.view.hidden = YES;
});
[searchBar resignFirstResponder];
}];
}