我能夠創建範圍酒吧UISearchController &設置它們的標題如何使用範圍酒吧UISearchController
resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.showsScopeBar = true
controller.searchBar.scopeButtonTitles = ["One", "two", "three"]
controller.searchBar.sizeToFit()
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
但實際上,我怎麼樣使用範圍吧。我目前的排序方法如下
func updateSearchResultsForSearchController(searchController: UISearchController) {
filteredTableData.removeAll(keepCapacity: false)
let searchPredicate = NSPredicate(format: "SELF CONTAINS[c] %@", searchController.searchBar.text)
let array = (tableData as NSArray).filteredArrayUsingPredicate(searchPredicate)
filteredTableData = array as! [String]
tableView.reloadData()
}
請給出更多的細節,你想要什麼輸出? – Mukesh
如果您看到我的代碼,我可以設置範圍欄標題。我想按三個類別對結果進行排序。 –
你有'tableData'中的任何數據,這將有助於使用範圍欄進行過濾嗎? 'tableData'只是一個字符串數組,如何幫助用「one」,「two」或「three」過濾。在上面提供的例子中的 –