简体   繁体   English

Swift UIViewController添加UISearchController

[英]Swift UIViewController add UISearchController

I'm very new to swift! 我是新来的迅速! Is it possible to add a UISearchController and UITableView to a UIViewController class? 是否可以将UISearchController和UITableView添加到UIViewController类? But only display the UITableView when there's search data to display to the user. 但是仅在有搜索数据要显示给用户时才显示UITableView。

I would like to implement something similar to the images below. 我想实现类似于下面的图片。 DISREGARD the interface design colors and data. 忽略界面设计的颜色和数据。

1. First View to display to user 1.要显示给用户的第一个视图

2. When user searches and data is returned display data in tableview 2.当用户搜索并返回数据时,在表视图中显示数据

Update 更新

I solved my problem.. I used the below links to give me an idea on how to do what I was looking for. 我解决了我的问题。.我使用下面的链接给我一个关于如何做我想要的事情的想法。

  1. thorntech.com/2016/01/how-to-search-for-location-using-apples-mapkit/ 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/ sweettutos.com/2015/09/30/how-to-use-the-google-places-autocomplete-api-with-google-maps-sdk-on-ios/

You will first need to create a UISearchController instance in the ViewController class and then integrate it with a searchBar delegate method for "textDidChange". 您首先需要在ViewController类中创建一个UISearchController实例,然后将其与“ textDidChange”的searchBar委托方法集成。 For the tableView you can create a separate file and use it to integrate with the UISearchController. 对于tableView,您可以创建一个单独的文件,并使用它与UISearchController集成。 It sounds complicated but it can be easily done. 听起来很复杂,但是很容易做到。 Check the below link for reference. 检查以下链接以供参考。 Although it is not exactly won't you are looking for but it can give you an idea. 虽然不是您要找的东西,但它可以给您一个想法。 Let me know if I am clear in my answer. 让我知道我的回答是否明确。 Happy to help. 乐意效劳。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM