简体   繁体   English

updateSearchResultsForSearchController无法与UIViewController一起使用

[英]updateSearchResultsForSearchController won't work with UIViewController

I'm following this tuto . 我正在关注此tuto
But I would like to add a Search Bar just upon the Live Photos & Info Segmented Control, then redirect the searched words to the Live Photos or Info views. 但我想在“ 实时照片和信息”分段控件上添加一个搜索栏 ,然后将搜索到的单词重定向到“ 实时照片”或“ 信息”视图。
I tried the Search Bar and Search Display Controller But fails because it needs a Table View . 我尝试了搜索栏和搜索显示控制器,但失败了,因为它需要表视图
Then I tried a Search Bar and tried to get the searched words by using this function: 然后,我尝试了一个搜索栏,并尝试使用此功能来获取搜索到的单词:

//MARK: - UISearchBarDelegate
func updateSearchResultsForSearchController(searchController: UISearchController)
{
    print("Looking for \(searchController.searchBar.text!)")
}

But it still not works. 但这仍然行不通。
Somebody already had this problem? 有人已经有这个问题了吗?

EDIT for @rptwsthi and @katleta3000: 编辑@rptwsthi和@ katleta3000:
Here are my delegates: UIViewController, UISearchBarDelegate, UISearchDisplayDelegate, UISearchResultsUpdating 这是我的代表:UIViewController,UISearchBarDelegate,UISearchDisplayDelegate,UISearchResultsUpdating

And I set it like that: 我将其设置为:

@IBOutlet var searchBar: UISearchBar!
override func viewDidLoad() {
  super.viewDidLoad()
  searchBar.delegate = self
}

UPDATE: 更新:
This works great: 这很好用:

func searchBarSearchButtonClicked( searchBar: UISearchBar)
{
        print("Looking at \(searchBar.text!)")

}

When I press Return searchBarSearchButtonClicked is executed but when I just type keys updateSearchResultsForSearchController is not executed, so I don't think it's due to delegate. 当我按下Return键时, searchBarSearchButtonClicked被执行,但是当我只键入键时, updateSearchResultsForSearchController没有被执行,所以我不认为这是由于委托。

It's appeared that func updateSearchResultsForSearchController(searchController: UISearchController) is only for TableView . 似乎func updateSearchResultsForSearchController(searchController: UISearchController)仅用于TableView
For View only it's func searchBar(searchBar: UISearchBar, textDidChange searchText: String) 仅适用于View,它是func searchBar(searchBar: UISearchBar, textDidChange searchText: String)

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

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