从数组过滤的两种方式

2016-01-29  本文已影响312人  龙翱天际
    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]
        self.tableView.reloadData()
    }
func updateSearchResultsForSearchController(searchController: UISearchController) { 
    let searchString = searchController.searchBar.text // 根据用户输入过滤数据到 
    filteredArray filteredArray = dataArray.filter({ (country) -> Bool in 
        let countryText: NSString = country
        return (countryText.rangeOfString(searchString, options: NSStringCompareOptions.CaseInsensitiveSearch).location) != NSNotFound }) 
    // 刷新 tableView 
    tblSearchResults.reloadData()
}
上一篇下一篇

猜你喜欢

热点阅读