未调用updatesearchresultsforsearchcontroller [英] updatesearchresultsforsearchcontroller not called

查看:122
本文介绍了未调用updatesearchresultsforsearchcontroller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道为什么在这里不称呼它吗?谢谢.我想我正确设置了代表.

Does anyone know why its not being called here? Thanks. I think I set up the delegate correctly.

class LocationSearchController: UIViewController, UISearchResultsUpdating, UINavigationBarDelegate, UISearchControllerDelegate {

let navigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 44))

var locationSearchController: UISearchController!

override func viewDidLoad() {
    super.viewDidLoad()


    locationSearchController = UISearchController(searchResultsController: nil)

    self.locationSearchController.loadViewIfNeeded()

    //sets up search controller
    self.locationSearchController.searchResultsUpdater = self
    self.locationSearchController.delegate = self
    definesPresentationContext = true
    //self.videoSearchController.searchBar.delegate = self

    //sets up nav bar
    navigationBar.backgroundColor = UIColor.blackColor()
    navigationBar.delegate = self



    navigationItem.titleView = locationSearchController.searchBar
    //leftButton.title = "Left"
    //navigationItem.leftBarButtonItem = leftButton
    navigationBar.items = [navigationItem]

    self.view.addSubview(navigationBar)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

func updateSearchResultsForSearchController(searchController: UISearchController) {
    print("search results updated 2")
}

}

任何想法都将不胜感激.我搜索了一会儿,但没有找到有关此问题的答案.

Any ideas would be much appreciated. I've searched for a little while and I failed to find a question about this that was answered.

推荐答案

我遇到了与iOS8相同的问题.这是一种解决方法,但可以解决此问题.

I ran into the same issue with iOS8. This is a workaround, but it will fix this.

  • 已使用LocationSearchController实现UISearchBarDelegate
  • 在viewDidLoad中添加以下行:

  • Have LocationSearchController implement UISearchBarDelegate
  • Add this line in viewDidLoad:

locationSearchController.searchBar.delegate = self

  • 添加此方法:

  • Add this method:

    func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
        updateSearchResultsForSearchController(locationSearchController)
    }
    

  • 这篇关于未调用updatesearchresultsforsearchcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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