How to add scope buttons in a UISearchController embedded in UINavigationController

孤者浪人 提交于 2019-12-02 09:32:35

You should try using the searchBar.scopeButtonTitles in your instance of UISearchController:

func initSearchController() {
   let mySearchController = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("SearchControllerId") as! SearchController

    searchController = UISearchController(searchResultsController: mySearchController)

    // Set Scope Bar Buttons
    searchController.searchBar.scopeButtonTitles = ["one", "two", "three"]
//    searchController.searchBar.showsScopeBar = true //if you want it always visible

    // Configure the UISearchController
    searchController.searchResultsUpdater = self
    searchController.searchBar.sizeToFit()
    tableView.tableHeaderView = searchController.searchBar

    searchController.delegate = self
    searchController.searchBar.delegate = self
    searchController.searchBar.placeholder = "data.." 
    searchController.hidesNavigationBarDuringPresentation = false
    searchController.dimsBackgroundDuringPresentation = true

    definesPresentationContext = true
}

No need to show or hide your scopeButtons in willAppear/didDisapear. This is set by: searchController.searchBar.showsScopeBar = true

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!