私は再利用可能なセルを持つテーブルビューを持っています。行が選択されているかどうかを示すチェックボックスとしてイメージビューを配置しました。行が選択されると、画像はそれに応じて正しく変化するが、再利用されている別のセルの画像も変化する。私はモデルを状態に保存し、それを反映させることによって試しましたが、indexPathは特定のセルの後で繰り返されるため、問題に取り組むことができません。セルを選択するときのチェックボックス機能iOSスウィフト
var allvacc: [[String:String]] = [
[
"id":"0",
"name":"BCG",
"timeAfterBirth":"1",
"description":"BCG stands for Bacillus Calmette–Guérin given to a baby 1 times as soon as possible after birth for protection against Tuberculosis",
"isChecked": "false",
],
[
"id":"1",
"name":"DPT-HepB-HiB - I",
"timeAfterBirth":"42",
"description":"DPT refers to a class of combination vaccines against three infectious diseases in humans: diphtheria, pertussis (whooping cough), and tetanus. Hepatitis B adn Hemophilius Influenza. This vaccine is taken 3 times in 6, 10 and 14 weeks.",
"isChecked": "false",
]
]
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
allVacc[indexPath.row]["isChecked"] = "true"
vaccineTableView.reloadData()
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
guard let checkListCell = tableView.dequeueReusableCellWithIdentifier("vaccineCheckListCell") as? VaccineCheckListCell else {
return UITableViewCell() }
checkListCell.vaccineNameLabel.text = vaccinationList[indexPath.row].name
if allVacc[indexPath.row]["isChecked"] == "true" {
checkListCell.vaccineStatusImage.image = UIImage(named: "ic_check_circle_yellow_48dp")
}
return checkListCell
}
ええ、それは感謝しました。 –
あなたのウェルカム! –