我的UISearchbar带有tableview,我想在搜索单元格上显示多个选择,并且即使用户更改搜索并将其存储在选定的数组中并且数组是字符串数组,也要保持选中状态。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
var imgtick : UIImageView? = cell.contentView.viewWithTag(4)as? UIImageView
if filterdata.count != 0
{
cell.textLabel?.text = filterdata[indexPath.row]
}
else{
cell.textLabel?.text = data[indexPath.row]
}
if checkarrMenu.contains(indexPath)
{
imgtick?.image = UIImage (named: "filter_check")
}
else
{
imgtick?.image = UIImage (named: "filter_uncheck")
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
let cell = tblview.cellForRow(at: indexPath) as! UITableViewCell
var imgtick : UIImageView? = cell.contentView.viewWithTag(4)as? UIImageView
let data1: NSData = UIImagePNGRepresentation(imgtick!.image!)! as NSData
let data2: NSData = UIImagePNGRepresentation(UIImage (named: "filter_uncheck")!)! as NSData
if checkarrMenu.contains(indexPath){
checkarrMenu.remove(indexPath)
imgtick?.image = UIImage (named: "filter_uncheck")
let usernametag = data[indexPath.row]
}
else
{
checkarrMenu.insert(indexPath)
imgtick?.image = UIImage (named: "filter_check")
let usernametag = data[indexPath.row]
}
}