teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

5

訂正

2020/07/02 21:54

投稿

退会済みユーザー
answer CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  表示されているセル全部を選択/選択解除するには、こんな感じかな?
16
16
  ```swift
17
- // 選択/全選択ボタンをタップした場合の処理
17
+ // 選択/全選択解除ボタンをタップした場合の処理
18
18
  @IBAction func btnDidTap(_ sender: UIButton) {
19
19
 
20
20
  switch sender.isSelected {

4

追記

2020/07/02 21:54

投稿

退会済みユーザー
answer CHANGED
@@ -30,4 +30,6 @@
30
30
  sender.isSelected.toggle()
31
31
  }
32
32
 
33
- ```
33
+ ```
34
+
35
+ 書いてて思いつきましたが、`tableView.allowsMultipleSelection = true`(複数選択可能)にして、それに対応した値の抽出->値渡しにしてあれば、全選択したあとは、特別に対応する必要がないですね。

3

訂正

2020/07/02 21:51

投稿

退会済みユーザー
answer CHANGED
@@ -17,17 +17,17 @@
17
17
  // 選択/全選択ボタンをタップした場合の処理
18
18
  @IBAction func btnDidTap(_ sender: UIButton) {
19
19
 
20
- switch sender.isSelected {
20
+ switch sender.isSelected {
21
- case true:
21
+ case true:
22
- items.enumerated().forEach {
22
+ items.enumerated().forEach {
23
- tableView.deselectRow(at: IndexPath(row: $0.offset, section: 0), animated: true)
23
+    tableView.deselectRow(at: IndexPath(row: $0.offset, section: 0), animated: true)
24
- }
25
- case false:
26
- items.enumerated().forEach {
27
- tableView.selectRow(at: IndexPath(row: $0.offset, section: 0), animated: true, scrollPosition: .none)
28
- }
29
24
  }
25
+ case false:
30
- sender.isSelected.toggle()
26
+ items.enumerated().forEach {
27
+ tableView.selectRow(at: IndexPath(row: $0.offset, section: 0), animated: true, scrollPosition: .none)
28
+ }
31
29
  }
30
+ sender.isSelected.toggle()
31
+ }
32
32
 
33
33
  ```

2

訂正

2020/07/02 21:39

投稿

退会済みユーザー
answer CHANGED
@@ -12,11 +12,22 @@
12
12
  ```
13
13
 
14
14
 
15
- 表示されているセル全部を選択するには、こんな感じかな?
15
+ 表示されているセル全部を選択/選択解除するには、こんな感じかな?
16
16
  ```swift
17
+ // 選択/全選択ボタンをタップした場合の処理
18
+ @IBAction func btnDidTap(_ sender: UIButton) {
19
+
20
+ switch sender.isSelected {
21
+ case true:
22
+ items.enumerated().forEach {
23
+ tableView.deselectRow(at: IndexPath(row: $0.offset, section: 0), animated: true)
24
+ }
25
+ case false:
26
+ items.enumerated().forEach {
27
+ tableView.selectRow(at: IndexPath(row: $0.offset, section: 0), animated: true, scrollPosition: .none)
28
+ }
29
+ }
30
+ sender.isSelected.toggle()
31
+ }
17
32
 
18
- tableView.indexPathsForVisibleCells.forEach {
19
- tableView.selectRow(at:$0, animated: true, scrollPosition: .none)
20
- }
21
-
22
33
  ```

1

追記

2020/07/02 21:38

投稿

退会済みユーザー
answer CHANGED
@@ -9,4 +9,14 @@
9
9
  return items.count // <- こんな感じになってる場合、このitemsを遷移先に渡す
10
10
  }
11
11
 
12
+ ```
13
+
14
+
15
+ 表示されているセル全部を選択するには、こんな感じかな?
16
+ ```swift
17
+
18
+ tableView.indexPathsForVisibleCells.forEach {
19
+ tableView.selectRow(at:$0, animated: true, scrollPosition: .none)
20
+ }
21
+
12
22
  ```