如何在用户点击搜索栏swift时显​​示tableview [英] How to show tableview when user taps searchbar swift

查看:62
本文介绍了如何在用户点击搜索栏swift时显​​示tableview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在用户点击搜索栏后以模态方式呈现tableview,然后能够让tableview呈现用户搜索的内容,例如Instagram的搜索功能。谷歌有很多关于如何制作搜索功能的教程,但没有关于如何在用户点击搜索栏后呈现桌面视图的教程。我应该怎么做?

I need a tableview to be presented modally after user taps on the search bar, and then be able to have the tableview present things the user searched, like Instagram's search function. There are plenty of tutorials on google about how to make a search feature, but none about how to present a tableview after the user taps on the search bar. How should I do that?

推荐答案

制作 UISearchController 出现在您选择的新 UITableView 中,执行以下操作:

To make the search results of a UISearchController appear in a new UITableView of your choice, do this:

let searchController = UISearchController(searchResultsController: myTableViewController)

而不是:

let searchController = UISearchController(searchResultsController: nil)

将视图控制器传递给构造函数允许 UISearchController 在适当的时间显示视图控制器(即搜索处于活动状态时)。这就是你需要做的。

Passing a view controller to the constructor allows the UISearchController to display the view controller at appropriate times (i.e. when the search is active). This is what you need to do.

传递 nil 意味着,我正在使用我自己的观点控制器(和表视图)

这篇关于如何在用户点击搜索栏swift时显​​示tableview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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