Клетки используются повторно. Всякий раз, когда вы условно устанавливаете свойство ячейки, вам необходимо сбросить это свойство в других случаях.
Самое простое решение - установить accessoryType
на .none
перед циклом (и перед if
).
Я также предлагаю немного оптимизировать заголовок. Вы звоните objArray[indexPath.section].sectionObj?[indexPath.row].title
много раз в этом коде. Сделай это один раз.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellClass") as! CellClass
let title = objArray[indexPath.section].sectionObj?[indexPath.row].title ?? "no title"
cell.titleLbl.text = title
cell.descLbl.text = objArray[indexPath.section].sectionObj?[indexPath.row].authors ?? "no authors"
cell.accessoryType = .none
for favorite in self.favourite {
if title == favourite.title {
cell.accessoryType = .checkmark
break // no need to keep looking
}
}
return cell
}
Я также показал много другой очистки кода.