質問編集履歴
2
進捗反映
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,17 +12,9 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
15
|
取得した配列`[IndexPaht]`は`reloadRows(at:with:)`で範囲指定したセルを更新するか、
|
20
16
|
|
21
17
|
セルを取得してから特定の値を書き換える目的で使いたいです。
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
18
|
|
27
19
|
|
28
20
|
|
@@ -30,7 +22,7 @@
|
|
30
22
|
|
31
23
|
```swift
|
32
24
|
|
33
|
-
let arrayOfArray = [["A", "B", "C", "D"],["D", "F"],["G", "H", "I"]]
|
25
|
+
let arrayOfArray = [["A", "B", "C", "D"], ["D", "F"], ["G", "H", "I"], ["J", "K"]]
|
34
26
|
|
35
27
|
|
36
28
|
|
@@ -46,9 +38,71 @@
|
|
46
38
|
|
47
39
|
|
48
40
|
|
41
|
+
```
|
49
42
|
|
50
43
|
|
51
44
|
|
45
|
+
一応以下のコードで実現できそうですが、もっとスマートな方法があれば教えてください。
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
```swift
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
let arrayOfArray = [["A", "B", "C", "D"], ["D", "F"], ["G", "H", "I"], ["J", "K"]]
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
let startIndex: IndexPath = [0, 3] // moveRowAtIndexpathとtoIndexPathの小さい方を代入する
|
58
|
+
|
59
|
+
let endIndex: IndexPath = [2, 1] // moveRowAtIndexpathとtoIndexPathの大きい方を代入する
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
var indexArray: [IndexPath] = []
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
for (section, array) in arrayOfArray.enumerated() {
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
for (row, _) in array.enumerated() {
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
if (section < startIndex.section) ||
|
76
|
+
|
77
|
+
(section <= startIndex.section && row < startIndex.row) ||
|
78
|
+
|
79
|
+
(section == endIndex.section && row > endIndex.row) ||
|
80
|
+
|
81
|
+
(section > endIndex.section) {
|
82
|
+
|
83
|
+
continue
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
let tempIndexPath: IndexPath = [section, row]
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
indexArray.append(tempIndexPath)
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
print("indexArray:",indexArray)
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
// => indexArray: [[0, 3], [1, 0], [1, 1], [2, 0], [2, 1]]
|
52
106
|
|
53
107
|
|
54
108
|
|
1
訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
let IndexArray: [IndexPath] = []
|
44
44
|
|
45
|
-
// 中身が、[[0,3],[
|
45
|
+
// 中身が、[[0,3],[1,0],[1,1],[2,0],[2,1]] となるようにしたい。
|
46
46
|
|
47
47
|
|
48
48
|
|