我使用from序列化方法从url中获取数据,并将每条记录存储在类的对象中,并在表vc中显示每条记录。
现在,我想使用搜索栏实现搜索,并观看了许多教程,这些教程比较了字符串类型数组和另一个字符串类型数组(数组中的硬编码值)。但根据我的需要,我的数据存储在类obj中,而不是硬编码的数据,来自该对象的数据显示在cellforrow上。细胞福罗包含。
if isSearching
{
cell.textLabel?.text = searchArray[indexPath.row] //.compName
cell.detailTextLabel?.text = searchArray[indexPath.row]
}
else{
cell.textLabel?.text = tempArray[indexPath.row].compName
cell.detailTextLabel?.text = tempArray[indexPath.row].complocation
}
return cell因此,如何实现搜索栏,获取跟踪错误。帮帮忙!这里我的类名是-> comp。searchArray是字符串数组,tempArray是包含类obj的数组。
发布于 2017-10-15 21:59:23
然后,您只需修改以前的搜索筛选器:
searchArray = tempArray.filter({$0.compName == searchBarClicked.text!})编译器告诉您,您不能将$0类型为comp与searchBarClicked.text (即String )进行比较,因此$0.compName将为String,因此可以使用==。
https://stackoverflow.com/questions/46759113
复制相似问题