【发布时间】:2015-05-15 07:47:28
【问题描述】:
我能够为 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()
}
【问题讨论】:
-
请提供更多细节,你想要什么输出?
-
如果您看到我的代码,我可以设置范围栏标题。我想按三个类别对结果进行排序。
-
tableData中是否有任何有助于使用范围栏进行过滤的数据?tableData只是一个字符串数组,这将如何帮助按“一”、“二”或“三”进行过滤。 -
在上面提供的示例中,tableData 是字符串数组。但我想有类别,例如奇数、偶数、全数。这就是范围栏的标题。
标签: ios uitableview swift uisearchcontroller