在SearchBar Tap上显示UISearchController的SearchResultsController [英] Show UISearchController's SearchResultsController on SearchBar Tap

查看:203
本文介绍了在SearchBar Tap上显示UISearchController的SearchResultsController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆