回答編集履歴

1

改善

2019/07/25 08:57

投稿

takabosoft
takabosoft

スコア8356

test CHANGED
@@ -1,8 +1,92 @@
1
- indexPathsForVisibleRowsだとたぶん見えてる部分しかチェック入らないすよ
1
+ indexPathsForVisibleRowsを対象に選択を行っても、「見えてる部分しかチェックりませんが、大丈夫しょうか
2
2
 
3
3
 
4
4
 
5
+ 1000行で試した結果を載せておきます。
6
+
7
+ ![イメージ説明](cdc82abbdbc5a77922fb563f33d68261.gif)
8
+
9
+
10
+
11
+ ```swift
12
+
13
+ import UIKit
14
+
15
+
16
+
17
+ class ViewController: UITableViewController {
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+ override func viewDidLoad() {
26
+
27
+ super.viewDidLoad()
28
+
29
+
30
+
31
+ tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
32
+
33
+ tableView.isEditing = true
34
+
35
+ tableView.allowsMultipleSelectionDuringEditing = true
36
+
37
+ }
38
+
39
+
40
+
41
+ override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
42
+
43
+ return 1000
44
+
45
+ }
46
+
47
+
48
+
49
+ override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
50
+
51
+ let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
52
+
53
+ cell.textLabel?.text = "(indexPath.row)"
54
+
55
+ return cell
56
+
57
+ }
58
+
59
+
60
+
61
+ @IBAction func hoge(_ sender: Any) {
62
+
63
+ guard let indexPaths = tableView.indexPathsForVisibleRows else { return }
64
+
65
+ for indexPath in indexPaths {
66
+
67
+ tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
68
+
69
+ }
70
+
71
+
72
+
73
+ /*for row in 0..<1000 {
74
+
75
+ tableView.selectRow(at: IndexPath(row: row, section: 0), animated: false, scrollPosition: .none)
76
+
77
+ }*/
78
+
79
+ }
80
+
81
+ }
82
+
83
+ ```
84
+
85
+
86
+
87
+ 「すべて選択」を実現したいのであれば、indexPathsForVisibleRowsではなく、全データに対応するIndexPathを自分で生成し、選択を行う必要があります。
88
+
5
- 未検証ですが、たぶん以下のようにしたほうが良かと
89
+ コードだとたぶん以下のようになると思ます
6
90
 
7
91
 
8
92