//Am not getting any search list of cells
//when am searching am getting empty array every time.
var actors = [["a0","b0","c0","d0"],["a1","b1","c1","d1"],["a2","b2","c2","d2"],["a3","b3","c3","d3"]]
var filterArr:[[String]] = []
func updateSearchResults(for searchController: UISearchController) {
print("Searching for text:----\(searchController.searchBar.text!)")
let predicate = NSPredicate(format: "SELF Contains[c] %@" , searchController.searchBar.text!)
filterArr = (actors as NSArray).filtered(using: predicate) as! [[String]]
print(filterArr)
}
问问题
50 次
1 回答
0
不要使用 Objective-C 的东西NSPredicate
,比如NSArray
当你不需要的时候。使用 Swiftfilter
和map
.
根据您在评论中的描述,您只想保留包含搜索文本的内部数组。你可以这样做:
filterArr = actors.filter { $0.contains(searchController.searchBar.text!) }
如果您只想保留包含搜索文本的项目的内部数组,请执行以下操作:
filterArr = actors.filter { $0.contains { $0.contains(searchController.searchBar.text!) } }
于 2019-05-17T11:52:08.770 回答