0
我有一個tableView,當選擇將圖像從一個更改爲另一個。這一切工作正常,但是當我選擇一個tableCell時,它會更改圖像,但是當我滾動它時,它也改變了我沒有選擇的另一個單元格的圖像。複選框上的複選框,斯威夫特,iOS
以下是我的代碼。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "FeaturesCell") as! FeaturesCell
cell.featuresLabel.text = self.items[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
pickedFeatures.append(items[indexPath.row])
let cell = tableView.cellForRow(at: indexPath) as! FeaturesCell
cell.checkImage.image = #imageLiteral(resourceName: "tick-inside-circle")
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
pickedFeatures.remove(at: pickedFeatures.index(of: items[indexPath.row])!)
let cell = tableView.cellForRow(at: indexPath) as! FeaturesCell
cell.checkImage.image = #imageLiteral(resourceName: "No-tick-inside-circle")
}
如果在did選擇功能中使用了detqueureusable單元,那麼它在選擇時根本不會改變圖片。
這會回答你的question-:HTTPS://stackoverflow.com/questions/43686354/filtertableviewcontroller-reloadrows-reloading-rows-only-on-first-call。您實際上需要保存複選框狀態。 –
這裏是我的演示https://www.dropbox.com/s/e43zk55surlwjlk/CollectionCkeck.zip?dl=0它與collectionview但邏輯可能會幫助你 –