gpt4 book ai didi

swift - UISearchBar func 与 Firebase 数据库和 swift

转载 作者:行者123 更新时间:2023-11-28 07:51:28 26 4
gpt4 key购买 nike

 @IBOutlet weak var tableViewhospitalss: UITableView!
@IBOutlet weak var searchBar: UISearchBar!


//list to store all the Hospitals
var hospitalsList = [hospitalsModel]()
var searchActive : Bool = false
var filtered:[String] = []

和函数

func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
searchActive = true
}

func searchBarTextDidEndEditing(searchBar: UISearchBar) {
searchActive = false
}

func searchBarCancelButtonClicked(searchBar: UISearchBar) {
searchActive = false
}

func searchBarSearchButtonClicked(searchBar: UISearchBar) {
searchActive = false
}

func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {

filtered = hospitalsList.filter ({ (text) -> Bool in
let temp: NSString = text! as NSString
let range = temp.range(of: searchText, options: NSString.CompareOptions.caseInsensitive)
return range.location != NSNotFound
})
if(filtered.count == 0){
searchActive = false;
} else {
searchActive = true;
}
self.tableViewhospitalss.reloadData()
}

enter image description here

任何人有任何建议请给我错误无法将类型“[hospitalsModel]”的值分配给类型“[String]”

最佳答案

问题是您正在尝试过滤并将“hospitalsModel”转换为字符串,因为过滤后的 var 是 [String],请尝试使用映射或过滤器 -> 返回相同的类型。

关于swift - UISearchBar func 与 Firebase 数据库和 swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49542976/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com