Swift UIViewController 添加 UISearchController

Swift UIViewController add UISearchController

我是 swift 的新手!是否可以将 UISearchController 和 UITableView 添加到 UIViewController class?但是只有在有搜索数据要显示给用户时才显示 UITableView。

我想实现类似于下图的东西。忽略界面设计颜色和数据。

1. First View to display to user

2. When user searches and data is returned display data in tableview

更新

我解决了我的问题。我使用下面的链接让我知道如何做我正在寻找的事情。

  1. thorntech.com/2016/01/how-to-search-for-location-using-apples-mapkit/
  2. sweettutos.com/2015/09/30/how-to-use-the-google-places-autocomplete-api-with-google-maps-sdk-on-ios/

您首先需要在 ViewController class 中创建一个 UISearchController 实例,然后将其与 "textDidChange" 的 searchBar 委托方法集成。对于 tableView,您可以创建一个单独的文件并使用它来与 UISearchController 集成。听起来很复杂,但很容易做到。 检查下面的 link 以供参考。虽然它不完全是你正在寻找的,但它可以给你一个想法。让我知道我的回答是否清楚。乐于助人。

http://sweettutos.com/2015/09/30/how-to-use-the-google-places-autocomplete-api-with-google-maps-sdk-on-ios/