How to add scope buttons in a UISearchController embedded in UINavigationController

后端 未结 1 771
礼貌的吻别
礼貌的吻别 2021-01-28 17:55

I have an App that is presenting a MKMapView embedded in a UINavigationController. In the UINavigationController I have put a UISearchController. When the User touch the UISearc

相关标签:
1条回答
  • 2021-01-28 18:48

    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

    0 讨论(0)
提交回复
热议问题