前提
色々と検索をして調べたのですが、TableViewのCellに複数チェックを入れる方法は沢山出てくるのですが、シングルのチェックマークを付ける方法がなかなか見つからず、ご質問させていただきました。
下記のようなコードを書くとCellが複数選択されてしまいます。
実現したいこと
Cellを選択すると対象のCell以外のチェックを全て外したいと思っています。
該当のソースコード
override func viewDidLoad() { tableView.allowsMultipleSelectionDuringEditing = false } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // 省略 if (rowListArray.contains(indexPath.row)){ cell.accessoryType = .checkmark }else{ cell.accessoryType = .none } return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if let index = rowListArray.firstIndex(of: indexPath.row) { rowListArray.remove(at: index) } else { rowListArray.append(indexPath.row) print(rowListArray) } tableView.reloadRows(at: [indexPath], with: .automatic) }
試したこと
自動で着くのかと思い、下記のコードを外すとチェックマークがつきません。
if (rowListArray.contains(indexPath.row)){
cell.accessoryType = .checkmark
}else{
cell.accessoryType = .none
}
tableView.allowsMultipleSelectionDuringEditingに関しては、trueとfalseも両方試しました。
よろしくお願いいたします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。