質問編集履歴

2

コードの追加と画像の追加

2017/10/20 01:27

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -522,8 +522,24 @@
522
522
 
523
523
 
524
524
 
525
+ ![イメージ説明](8b496acd3e572b6d49e1b80617fa2787.png)
526
+
527
+
528
+
525
529
 
526
530
 
527
531
  **//コード変更後**
528
532
 
529
533
  cellforRowAtにチェックマークの処理を書くとタップしてチェックマークつけたいのにタップしても反応しなくなります。
534
+
535
+
536
+
537
+ ```ここに言語を入力
538
+
539
+ tableView.reloadRows(at: [indexPath], with: .none)
540
+
541
+ ```
542
+
543
+
544
+
545
+ こうすることによってタップしてチェックマークをつけれるようになったのですが、なぜかcellを追加すると[cell 追加 ボタン]だけ勝手にチェックがついてしまうのですがなぜなのでしょうか?

1

コードの修正

2017/10/20 01:27

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -166,8 +166,6 @@
166
166
 
167
167
  cell.textLabel?.text = item.name
168
168
 
169
- //cell.textLabel?.text = kei[indexPath.row]
170
-
171
169
  cell.textLabel?.textColor = UIColor.red
172
170
 
173
171
  cell.backgroundColor = UIColor.black
@@ -180,6 +178,8 @@
180
178
 
181
179
  if cell.textLabel?.text != "cell 追加 ボタン" {
182
180
 
181
+      cell.accessoryType = item.complete ? .checkmark : .none
182
+
183
183
  cell.textLabel?.textColor = UIColor.black
184
184
 
185
185
  cell.backgroundColor = UIColor.yellow
@@ -204,8 +204,6 @@
204
204
 
205
205
 
206
206
 
207
- /*if kei.count > (indexPath.row + 1)使うには func tableView(_ tableView: UITableView, didSelectRowAtIndexPath: IndexPath){ を func tableView(_ tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) -> IndexPath? {*/
208
-
209
207
  func tableView(_ tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) -> IndexPath? {
210
208
 
211
209
 
@@ -216,7 +214,7 @@
216
214
 
217
215
  if cell?.textLabel?.text != "cell 追加 ボタン"{
218
216
 
219
- cell?.accessoryType = cell?.accessoryType == .checkmark ? .none : .checkmark
217
+ kei[indexPath.row].toggle()
220
218
 
221
219
  tableView.deselectRow(at: indexPath, animated: true)
222
220
 
@@ -521,3 +519,11 @@
521
519
  **試したこと**
522
520
 
523
521
  https://teratail.com/questions/94578を参考にし、色々試した中で構造体を使ってみたのですがcellの追加時にやっぱりにチェックマークの位置がずれて困っています。
522
+
523
+
524
+
525
+
526
+
527
+ **//コード変更後**
528
+
529
+ cellforRowAtにチェックマークの処理を書くとタップしてチェックマークつけたいのにタップしても反応しなくなります。