【发布时间】:2018-04-07 07:45:41
【问题描述】:
我正在使用下面的数组结构来创建一个带有节的 tableView
struct words {
var sectionName : String!
var coptic : [String]!
var english : [String]!
}
var array = [words]()
var filtered = [words]()
array = [words(sectionName: "", coptic: [""], English: [""])]
我想使用类似代码的搜索控制器
func updateSearchResults(for searchController: UISearchController) {
// If we haven't typed anything into the search bar then do not filter the results
if searchController.searchBar.text! == "" {
filtered = array
} else {
// Filter the results
filtered = array.filter { $0.coptic.lowercased().contains(searchController.searchBar.text!.lowercased()) }
}
不幸的是,因为 coptic 是一个 [String],而不仅仅是一个 String,所以代码不起作用。有没有办法修改它以便能够过滤对科普特小节的搜索?
【问题讨论】:
标签: arrays swift tableview uisearchbar sub-array