我有一个表视图,用户可以选择单元格但是这个表视图类不是表视图控制器所以我在表视图中使用空和填充图像用于非选定和选择的单元格但问题是当我选择了一些单元格时向下滚动,当我再次向上滚动时,我选择的单元格将显示非选择但是这些单元格被选中但是我看到的是这些单元格未被选中! 请记住我使用的也是显示方法但是问题没有解决 这是我的代码
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let filterSubTitleCell = self.filteringSubTitle.dequeueReusableCell(withIdentifier: "filteringSubTitleCell", for: indexPath) as! filteringSubTitleCell
filterSubTitleCell.selectionStyle = .none
if listOfFilterJobs[lastIndex].selectedItem != nil{
if listOfFilterJobs[lastIndex].selectedItem?.count != 0 {
if (listOfFilterJobs[lastIndex].selectedItem?.contains(indexPath))!{
filterSubTitleCell.checkImage.image = UIImage(named: "checkfill")
filterSubTitleCell.contentView.backgroundColor = UIColor.white
} else {
filterSubTitleCell.checkImage.image = UIImage(named: "checkempty")
}
} else {
filterSubTitleCell.checkImage.image = UIImage(named: "checkempty")
}
}else {
filterSubTitleCell.checkImage.image = UIImage(named: "checkempty")
}
filterSubTitleCell.subTitle.text = arrayData[indexPath.row].title
filterSubTitleCell.subTitle?.adjustsFontSizeToFitWidth = true
filterSubTitleCell.subTitle?.minimumScaleFactor = 0.5
return filterSubTitleCell
}