问题描述
我正在使用UISearchController而不是UISearchDisplayController,我想立即在SearchBar Tap上显示SearchResultController。现在它显示如下(当我点击搜索栏时):
I am using UISearchController not UISearchDisplayController, and I want to show SearchResultController on SearchBar Tap right away. Right now it's showing like this (when I tap on the search bar):
推荐答案
当结果为空时, UISearchController
的 viewController
仍然是隐藏的。这就是为什么我们不得不使用 UISearchControllerDelegate
的 willPresentSearchController:
When results are empty, UISearchController
's viewController
is still hidden. That's why we have to fiddle our way around using UISearchControllerDelegate
's willPresentSearchController:
self.searchController.delegate = self;
在ViewController中实现 willPresentSearchController:
:
Implement willPresentSearchController:
in your ViewController:
- (void)willPresentSearchController:(UISearchController *)searchController
{
dispatch_async(dispatch_get_main_queue(), ^{
searchController.searchResultsController.view.hidden = NO;
});
}
异步调度是必要的,否则它将被内部行为覆盖。你可以在这里看一下并使用动画让表格视图淡入。
The async dispatch is necessary, because otherwise it will be overridden by the internal behavior. You could go fancy here and use an animation to have the table view fade in.
- (void)didPresentSearchController:(UISearchController *)searchController
{
searchController.searchResultsController.view.hidden = NO;
}
这篇关于在SearchBar Tap上显示UISearchController的SearchResultsController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!