質問編集履歴
6
訂正
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,9 +8,6 @@
|
|
8
8
|
↓`Section:2`(青い部分)がパっと表示される、なんとかフェードインとかスライドインみたくならないでしょうか?
|
9
9
|

|
10
10
|
|
11
|
-
↓`debug`-`SlowAnimations`/`Section:2`(青い部分)がパっと表示される
|
12
|
-

|
13
|
-
|
14
11
|
```swift
|
15
12
|
import UIKit
|
16
13
|
|
5
ソースを編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,6 +12,8 @@
|
|
12
12
|

|
13
13
|
|
14
14
|
```swift
|
15
|
+
import UIKit
|
16
|
+
|
15
17
|
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
|
16
18
|
|
17
19
|
//MARK: -- properties --
|
@@ -22,51 +24,6 @@
|
|
22
24
|
//MARK: -- Outlets --
|
23
25
|
@IBOutlet weak var testTableView: UITableView!
|
24
26
|
|
25
|
-
// セクションヘッダーを取り除く処理
|
26
|
-
@IBAction func removeSectionBtnTapped(_ sender: UIButton) {
|
27
|
-
guard let targetSection = sender.superview?.superview?.tag else { return }
|
28
|
-
let preTargetSection = targetSection - 1
|
29
|
-
|
30
|
-
if !(targetSection == 0) {
|
31
|
-
|
32
|
-
print("removeSectionBtnTapped")
|
33
|
-
|
34
|
-
// 配列操作
|
35
|
-
let targetSectionArray = arrayOfArray[targetSection]
|
36
|
-
arrayOfArray.remove(at: targetSection)
|
37
|
-
let preTargetSectionArray = arrayOfArray[preTargetSection]
|
38
|
-
arrayOfArray[preTargetSection] = preTargetSectionArray + targetSectionArray
|
39
|
-
|
40
|
-
// 挿入するインデックスパスの配列を作る
|
41
|
-
let insertIndexes: [IndexPath] =
|
42
|
-
(preTargetSectionArray.count ..< arrayOfArray[preTargetSection].count).map {[preTargetSection, $0]}
|
43
|
-
|
44
|
-
// tableView操作
|
45
|
-
testTableView.beginUpdates()
|
46
|
-
testTableView.deleteSections(IndexSet(integer: targetSection), with: .none)
|
47
|
-
testTableView.insertRows(at: insertIndexes, with: .fade)
|
48
|
-
testTableView.endUpdates()
|
49
|
-
|
50
|
-
// リロードしないとHeaderViewが表示されなくなる/tableView(_: viewForHeaderInSection) -> UIView?が呼ばれない
|
51
|
-
testTableView.reloadData()
|
52
|
-
|
53
|
-
/* tableViewをリロードした場合の呼び出し回数/Tap"FFFF"
|
54
|
-
removeSectionBtnTapped
|
55
|
-
numberOfSection/ 3
|
56
|
-
numberOfSection/ 3
|
57
|
-
numberOfSection/ 3
|
58
|
-
generateSection
|
59
|
-
generateSection
|
60
|
-
*/
|
61
|
-
|
62
|
-
/* tableViewをリロードしない場合の呼び出し回数/Tap"FFFF"
|
63
|
-
removeSectionBtnTapped
|
64
|
-
numberOfSection/ 3
|
65
|
-
numberOfSection/ 3
|
66
|
-
*/
|
67
|
-
}
|
68
|
-
}
|
69
|
-
|
70
27
|
// セクションヘッダーを追加する処理
|
71
28
|
@IBAction func addSectionHeaderView(_ sender: UILongPressGestureRecognizer) {
|
72
29
|
if(sender.state == UIGestureRecognizer.State.began) {
|
@@ -103,14 +60,14 @@
|
|
103
60
|
// リロードしないとHeaderViewが表示されなくなる/tableView(_: viewForHeaderInSection) -> UIView?が呼ばれない
|
104
61
|
testTableView.reloadData()
|
105
62
|
|
106
|
-
|
63
|
+
/* tableViewをリロードしない場合の呼び出し回数/LongPress"FFFF"
|
107
64
|
CellLongPressed/addSectionHeaderView
|
108
65
|
numberOfSection/ 4
|
109
66
|
numberOfSection/ 4
|
110
67
|
generateSection
|
111
|
-
|
68
|
+
*/
|
112
69
|
|
113
|
-
|
70
|
+
/* tableViewをリロードした場合の呼び出し回数/LongPress"FFFF"
|
114
71
|
CellLongPressed/addSectionHeaderView
|
115
72
|
numberOfSection/ 4
|
116
73
|
numberOfSection/ 4
|
@@ -119,11 +76,56 @@
|
|
119
76
|
generateSection
|
120
77
|
generateSection
|
121
78
|
generateSection
|
122
|
-
|
79
|
+
*/
|
123
80
|
}
|
124
81
|
}
|
125
82
|
}
|
126
83
|
|
84
|
+
// セクションヘッダーを取り除く処理
|
85
|
+
@IBAction func removeSectionBtnTapped(_ sender: UIButton) {
|
86
|
+
guard let targetSection = sender.superview?.superview?.tag else { return }
|
87
|
+
let preTargetSection = targetSection - 1
|
88
|
+
|
89
|
+
if !(targetSection == 0) {
|
90
|
+
|
91
|
+
print("removeSectionBtnTapped")
|
92
|
+
|
93
|
+
// 配列操作
|
94
|
+
let targetSectionArray = arrayOfArray[targetSection]
|
95
|
+
arrayOfArray.remove(at: targetSection)
|
96
|
+
let preTargetSectionArray = arrayOfArray[preTargetSection]
|
97
|
+
arrayOfArray[preTargetSection] = preTargetSectionArray + targetSectionArray
|
98
|
+
|
99
|
+
// 挿入するインデックスパスの配列を作る
|
100
|
+
let insertIndexes: [IndexPath] =
|
101
|
+
(preTargetSectionArray.count ..< arrayOfArray[preTargetSection].count).map {[preTargetSection, $0]}
|
102
|
+
|
103
|
+
// tableView操作
|
104
|
+
testTableView.beginUpdates()
|
105
|
+
testTableView.deleteSections(IndexSet(integer: targetSection), with: .none)
|
106
|
+
testTableView.insertRows(at: insertIndexes, with: .fade)
|
107
|
+
testTableView.endUpdates()
|
108
|
+
|
109
|
+
// リロードしないとHeaderViewが表示されなくなる/tableView(_: viewForHeaderInSection) -> UIView?が呼ばれない
|
110
|
+
testTableView.reloadData()
|
111
|
+
|
112
|
+
/* tableViewをリロードした場合の呼び出し回数/Tap"FFFF"
|
113
|
+
removeSectionBtnTapped
|
114
|
+
numberOfSection/ 3
|
115
|
+
numberOfSection/ 3
|
116
|
+
numberOfSection/ 3
|
117
|
+
generateSection
|
118
|
+
generateSection
|
119
|
+
*/
|
120
|
+
|
121
|
+
/* tableViewをリロードしない場合の呼び出し回数/Tap"FFFF"
|
122
|
+
removeSectionBtnTapped
|
123
|
+
numberOfSection/ 3
|
124
|
+
numberOfSection/ 3
|
125
|
+
*/
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
127
129
|
//MARK: - UITableViewDataSource -
|
128
130
|
|
129
131
|
//MARK: -- Section --
|
4
訂正
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,10 +5,10 @@
|
|
5
5
|
|
6
6
|
動作は、ロングプレスしたセルの上に`SectionHeader`を挿入し、`SectionHeader`にある☓ボタンで該当`SectionHeader`を削除しています。
|
7
7
|
|
8
|
-
↓`Section:2`がパっと表示される、なんとかフェードインとかスライドインみたくならないでしょうか?
|
8
|
+
↓`Section:2`(青い部分)がパっと表示される、なんとかフェードインとかスライドインみたくならないでしょうか?
|
9
9
|

|
10
10
|
|
11
|
-
↓`debug`-`SlowAnimations`表示
|
11
|
+
↓`debug`-`SlowAnimations`/`Section:2`(青い部分)がパっと表示される
|
12
12
|

|
13
13
|
|
14
14
|
```swift
|
3
進捗を反映
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
いつもお世話になります。
|
2
2
|
|
3
|
-
`UITabelView`の
|
3
|
+
`UITabelView`/`SectionHeaderView`の挿入/削除をアニメーション付きで表示しようとしているのですが、`SectionHeaderView`(青い部分)の挿入だけ思ったようにアニメーションがかかりません。
|
4
|
-
|
4
|
+
どこを見直せばいいでしょうか、また方向性が根本から間違っているのでしょうか?
|
5
5
|
|
6
|
-
|
6
|
+
動作は、ロングプレスしたセルの上に`SectionHeader`を挿入し、`SectionHeader`にある☓ボタンで該当`SectionHeader`を削除しています。
|
7
7
|
|
8
|
-
|
8
|
+
↓`Section:2`がパっと表示される、なんとかフェードインとかスライドインみたくならないでしょうか?
|
9
|
+

|
9
10
|
|
11
|
+
↓`debug`-`SlowAnimations`表示
|
10
|
-

|
11
13
|
|
12
|
-
|
13
14
|
```swift
|
14
15
|
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
|
15
16
|
|
@@ -23,56 +24,123 @@
|
|
23
24
|
|
24
25
|
// セクションヘッダーを取り除く処理
|
25
26
|
@IBAction func removeSectionBtnTapped(_ sender: UIButton) {
|
26
|
-
guard let
|
27
|
+
guard let targetSection = sender.superview?.superview?.tag else { return }
|
28
|
+
let preTargetSection = targetSection - 1
|
29
|
+
|
27
|
-
if !(
|
30
|
+
if !(targetSection == 0) {
|
28
31
|
|
29
|
-
|
32
|
+
print("removeSectionBtnTapped")
|
30
|
-
let insertArray = arrayOfArray[numOfSection - 1] + arrayOfArray[numOfSection]
|
31
33
|
|
34
|
+
// 配列操作
|
35
|
+
let targetSectionArray = arrayOfArray[targetSection]
|
32
|
-
arrayOfArray.remove(at:
|
36
|
+
arrayOfArray.remove(at: targetSection)
|
37
|
+
let preTargetSectionArray = arrayOfArray[preTargetSection]
|
33
|
-
arrayOfArray
|
38
|
+
arrayOfArray[preTargetSection] = preTargetSectionArray + targetSectionArray
|
34
39
|
|
40
|
+
// 挿入するインデックスパスの配列を作る
|
41
|
+
let insertIndexes: [IndexPath] =
|
35
|
-
|
42
|
+
(preTargetSectionArray.count ..< arrayOfArray[preTargetSection].count).map {[preTargetSection, $0]}
|
36
43
|
|
44
|
+
// tableView操作
|
45
|
+
testTableView.beginUpdates()
|
46
|
+
testTableView.deleteSections(IndexSet(integer: targetSection), with: .none)
|
47
|
+
testTableView.insertRows(at: insertIndexes, with: .fade)
|
48
|
+
testTableView.endUpdates()
|
49
|
+
|
50
|
+
// リロードしないとHeaderViewが表示されなくなる/tableView(_: viewForHeaderInSection) -> UIView?が呼ばれない
|
37
51
|
testTableView.reloadData()
|
52
|
+
|
53
|
+
/* tableViewをリロードした場合の呼び出し回数/Tap"FFFF"
|
54
|
+
removeSectionBtnTapped
|
55
|
+
numberOfSection/ 3
|
56
|
+
numberOfSection/ 3
|
57
|
+
numberOfSection/ 3
|
58
|
+
generateSection
|
59
|
+
generateSection
|
60
|
+
*/
|
61
|
+
|
62
|
+
/* tableViewをリロードしない場合の呼び出し回数/Tap"FFFF"
|
63
|
+
removeSectionBtnTapped
|
64
|
+
numberOfSection/ 3
|
65
|
+
numberOfSection/ 3
|
66
|
+
*/
|
38
67
|
}
|
39
68
|
}
|
40
69
|
|
41
70
|
// セクションヘッダーを追加する処理
|
42
|
-
@IBAction func
|
71
|
+
@IBAction func addSectionHeaderView(_ sender: UILongPressGestureRecognizer) {
|
43
72
|
if(sender.state == UIGestureRecognizer.State.began) {
|
44
73
|
} else if (sender.state == UIGestureRecognizer.State.ended) {
|
45
74
|
|
46
75
|
let point = sender.location(in: testTableView)
|
47
76
|
guard let indexPath = testTableView.indexPathForRow(at: point) else { return }
|
48
77
|
|
78
|
+
print("CellLongPressed/addSectionHeaderView")
|
79
|
+
|
49
80
|
if !(indexPath.row == 0) {
|
81
|
+
// 配列操作
|
50
82
|
let targetArray = arrayOfArray[indexPath.section]
|
51
83
|
let firsrOfTargetArray = targetArray.prefix(indexPath.row)
|
52
84
|
let secondOfTargetArray = targetArray.dropFirst(indexPath.row)
|
53
|
-
|
54
85
|
arrayOfArray.remove(at: indexPath.section)
|
55
|
-
|
56
|
-
arrayOfArray.insert(secondOfTargetArray.map{$0}, at: indexPath.section)
|
57
86
|
arrayOfArray.insert(firsrOfTargetArray.map{$0}, at: indexPath.section)
|
87
|
+
arrayOfArray.insert(secondOfTargetArray.map{$0}, at: indexPath.section + 1)
|
58
88
|
|
89
|
+
// 削除するインデックスパスの配列を作る
|
90
|
+
let deleteIndexes: [IndexPath] =
|
91
|
+
(indexPath.row ..< targetArray.count).map {[indexPath.section, $0]}
|
92
|
+
|
93
|
+
//TODO: -- ここがうまくいかない/アニメーションの組み合わせ? --
|
94
|
+
// tableView操作
|
95
|
+
testTableView.beginUpdates()
|
96
|
+
|
97
|
+
//testTableView.deleteSections(IndexSet(integer: indexPath.section), with: .none)
|
98
|
+
//testTableView.insertSections(IndexSet(integer: indexPath.section), with: .none)
|
99
|
+
|
100
|
+
testTableView.deleteRows(at: deleteIndexes, with: .fade)
|
101
|
+
testTableView.insertSections(IndexSet(integer: indexPath.section + 1), with: .none)
|
102
|
+
testTableView.endUpdates()
|
103
|
+
// リロードしないとHeaderViewが表示されなくなる/tableView(_: viewForHeaderInSection) -> UIView?が呼ばれない
|
59
104
|
testTableView.reloadData()
|
105
|
+
|
106
|
+
/* tableViewをリロードしない場合の呼び出し回数/LongPress"FFFF"
|
107
|
+
CellLongPressed/addSectionHeaderView
|
108
|
+
numberOfSection/ 4
|
109
|
+
numberOfSection/ 4
|
110
|
+
generateSection
|
111
|
+
*/
|
112
|
+
|
113
|
+
/* tableViewをリロードした場合の呼び出し回数/LongPress"FFFF"
|
114
|
+
CellLongPressed/addSectionHeaderView
|
115
|
+
numberOfSection/ 4
|
116
|
+
numberOfSection/ 4
|
117
|
+
generateSection
|
118
|
+
numberOfSection/ 4
|
119
|
+
generateSection
|
120
|
+
generateSection
|
121
|
+
generateSection
|
122
|
+
*/
|
60
123
|
}
|
61
124
|
}
|
62
125
|
}
|
63
126
|
|
64
|
-
|
65
127
|
//MARK: - UITableViewDataSource -
|
66
128
|
|
67
129
|
//MARK: -- Section --
|
68
130
|
|
69
131
|
// numberOfSection
|
70
132
|
func numberOfSections(in tableView: UITableView) -> Int {
|
133
|
+
|
134
|
+
print("numberOfSection/",arrayOfArray.count)
|
135
|
+
|
71
136
|
return arrayOfArray.count
|
72
137
|
}
|
73
138
|
|
74
139
|
// generateSection
|
75
140
|
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
141
|
+
|
142
|
+
print("generateSection")
|
143
|
+
|
76
144
|
let sectionHeaderView = testTableView.dequeueReusableCell(withIdentifier: "Section") as! SectionHeaderCell
|
77
145
|
|
78
146
|
sectionHeaderView.tag = section
|
@@ -97,9 +165,11 @@
|
|
97
165
|
}
|
98
166
|
|
99
167
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
100
|
-
let cell = testTableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
|
168
|
+
let cell = testTableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CustomCell
|
101
|
-
|
169
|
+
let cellLabelStr = arrayOfArray[indexPath.section][indexPath.row]
|
102
170
|
|
171
|
+
cell.setValueToCell(cellLabelStr: cellLabelStr)
|
172
|
+
|
103
173
|
return cell
|
104
174
|
}
|
105
175
|
|
@@ -120,117 +190,5 @@
|
|
120
190
|
// Do any additional setup after loading the view, typically from a nib.
|
121
191
|
}
|
122
192
|
}
|
123
|
-
```
|
124
193
|
|
125
|
-
方向性が間違っているのかもしれませんが、
|
126
|
-
`beginUpdates()`〜`endUpdates()`の内部で削除->挿入をすればよいのかと進めているのですが、
|
127
|
-
SectionHeaderをインサートするアニメーションがうまく動きません。
|
128
|
-
(SectionHeaderを削除するアニメーションは我慢できる程度には動かすことができました。)
|
129
|
-
|
130
|
-

|
131
|
-
|
132
|
-
```swift
|
133
|
-
// セクションヘッダーを取り除く処理
|
134
|
-
@IBAction func removeSectionBtnTapped(_ sender: UIButton) {
|
135
|
-
guard let targetSection = sender.superview?.superview?.tag else { return }
|
136
|
-
let preTargetSection = targetSection - 1
|
137
|
-
|
138
|
-
if !(targetSection == 0) {
|
139
|
-
|
140
|
-
print("removeSectionBtnTapped")
|
141
|
-
|
142
|
-
// 配列操作
|
143
|
-
let targetSectionArray = arrayOfArray[targetSection]
|
144
|
-
arrayOfArray.remove(at: targetSection)
|
145
|
-
let preTargetSectionArray = arrayOfArray[preTargetSection]
|
146
|
-
arrayOfArray[preTargetSection] = preTargetSectionArray + targetSectionArray
|
147
|
-
|
148
|
-
// 挿入するインデックスパスの配列を作る
|
149
|
-
let insertIndexes: [IndexPath] =
|
150
|
-
(preTargetSectionArray.count ..< arrayOfArray[preTargetSection].count).map {[preTargetSection, $0]}
|
151
|
-
|
152
|
-
// tableViewを編集する
|
153
|
-
testTableView.beginUpdates()
|
154
|
-
testTableView.deleteSections(IndexSet(integer: targetSection), with: .none)
|
155
|
-
testTableView.insertRows(at: insertIndexes, with: .fade)
|
156
|
-
testTableView.endUpdates()
|
157
|
-
// リロードしないとHeaderViewが表示されなくなる/なぜ?
|
158
|
-
testTableView.reloadData()
|
159
|
-
|
160
|
-
/* tableViewをリロードした場合の呼び出し回数/Tap"FFFF"
|
161
|
-
removeSectionBtnTapped
|
162
|
-
numberOfSection
|
163
|
-
numberOfSection
|
164
|
-
numberOfSection
|
165
|
-
generateSection
|
166
|
-
generateSection
|
167
|
-
*/
|
168
|
-
|
169
|
-
/* tableViewをリロードしない場合の呼び出し回数/Tap"FFFF"
|
170
|
-
removeSectionBtnTapped
|
171
|
-
numberOfSection
|
172
|
-
numberOfSection
|
173
|
-
*/
|
174
|
-
|
175
|
-
}
|
176
|
-
}
|
177
|
-
|
178
|
-
// セクションヘッダーを追加する処理
|
179
|
-
@IBAction func addSectionHeaderView(_ sender: UILongPressGestureRecognizer) {
|
180
|
-
if(sender.state == UIGestureRecognizer.State.began) {
|
181
|
-
} else if (sender.state == UIGestureRecognizer.State.ended) {
|
182
|
-
|
183
|
-
let point = sender.location(in: testTableView)
|
184
|
-
guard let indexPath = testTableView.indexPathForRow(at: point) else { return }
|
185
|
-
|
186
|
-
print("CellLongPressed/addSectionHeaderView")
|
187
|
-
|
188
|
-
if !(indexPath.row == 0) {
|
189
|
-
// 配列操作
|
190
|
-
let targetArray = arrayOfArray[indexPath.section]
|
191
|
-
let firsrOfTargetArray = targetArray.prefix(indexPath.row)
|
192
|
-
let secondOfTargetArray = targetArray.dropFirst(indexPath.row)
|
193
|
-
arrayOfArray.remove(at: indexPath.section)
|
194
|
-
arrayOfArray.insert(firsrOfTargetArray.map{$0}, at: indexPath.section)
|
195
|
-
arrayOfArray.insert(secondOfTargetArray.map{$0}, at: indexPath.section + 1)
|
196
|
-
|
197
|
-
// 削除するインデックスパスの配列を作る
|
198
|
-
let deleteIndexes: [IndexPath] =
|
199
|
-
(indexPath.row ..< targetArray.count).map {[indexPath.section, $0]}
|
200
|
-
|
201
|
-
|
202
|
-
//TODO: -- ここがうまくいかない/アニメーションの組み合わせの考察 --
|
203
|
-
// tableView操作
|
204
|
-
testTableView.beginUpdates()
|
205
|
-
|
206
|
-
//testTableView.deleteSections(IndexSet(integer: indexPath.section), with: .none)
|
207
|
-
//testTableView.insertSections(IndexSet(integer: indexPath.section), with: .none)
|
208
|
-
|
209
|
-
testTableView.deleteRows(at: deleteIndexes, with: .none)
|
210
|
-
testTableView.insertSections(IndexSet(integer: indexPath.section + 1), with: .top)
|
211
|
-
testTableView.endUpdates()
|
212
|
-
// リロードしないとHeaderViewが表示されなくなる/なぜ?
|
213
|
-
testTableView.reloadData()
|
214
|
-
|
215
|
-
/* tableViewをリロードしない場合の呼び出し回数/LongPress"FFFF"
|
216
|
-
CellLongPressed/addSectionHeaderView
|
217
|
-
numberOfSection
|
218
|
-
numberOfSection
|
219
|
-
generateSection
|
220
|
-
*/
|
221
|
-
|
222
|
-
/* tableViewをリロードした場合の呼び出し回数/LongPress"FFFF"
|
223
|
-
CellLongPressed/addSectionHeaderView
|
224
|
-
numberOfSection
|
225
|
-
numberOfSection
|
226
|
-
generateSection
|
227
|
-
numberOfSection
|
228
|
-
generateSection
|
229
|
-
generateSection
|
230
|
-
generateSection
|
231
|
-
*/
|
232
|
-
|
233
|
-
}
|
234
|
-
}
|
235
|
-
}
|
236
194
|
```
|
2
訂正
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,8 +18,6 @@
|
|
18
18
|
["IIII", "JJJJ", "KKKK", "LLLL", "MMMM", "OOOO", "PPPP", "QQQQ"],
|
19
19
|
["RRRR", "SSSS", "TTTT", "UUUU", "VVVV", "XXXX", "YYYY", "ZZZZ"]]
|
20
20
|
|
21
|
-
var sectionNumberArray: [Int] = [1,2]
|
22
|
-
|
23
21
|
//MARK: -- Outlets --
|
24
22
|
@IBOutlet weak var testTableView: UITableView!
|
25
23
|
|
@@ -139,6 +137,8 @@
|
|
139
137
|
|
140
138
|
if !(targetSection == 0) {
|
141
139
|
|
140
|
+
print("removeSectionBtnTapped")
|
141
|
+
|
142
142
|
// 配列操作
|
143
143
|
let targetSectionArray = arrayOfArray[targetSection]
|
144
144
|
arrayOfArray.remove(at: targetSection)
|
@@ -156,6 +156,22 @@
|
|
156
156
|
testTableView.endUpdates()
|
157
157
|
// リロードしないとHeaderViewが表示されなくなる/なぜ?
|
158
158
|
testTableView.reloadData()
|
159
|
+
|
160
|
+
/* tableViewをリロードした場合の呼び出し回数/Tap"FFFF"
|
161
|
+
removeSectionBtnTapped
|
162
|
+
numberOfSection
|
163
|
+
numberOfSection
|
164
|
+
numberOfSection
|
165
|
+
generateSection
|
166
|
+
generateSection
|
167
|
+
*/
|
168
|
+
|
169
|
+
/* tableViewをリロードしない場合の呼び出し回数/Tap"FFFF"
|
170
|
+
removeSectionBtnTapped
|
171
|
+
numberOfSection
|
172
|
+
numberOfSection
|
173
|
+
*/
|
174
|
+
|
159
175
|
}
|
160
176
|
}
|
161
177
|
|
@@ -167,9 +183,8 @@
|
|
167
183
|
let point = sender.location(in: testTableView)
|
168
184
|
guard let indexPath = testTableView.indexPathForRow(at: point) else { return }
|
169
185
|
|
186
|
+
print("CellLongPressed/addSectionHeaderView")
|
170
187
|
|
171
|
-
print("addSectionHeaderView")
|
172
|
-
|
173
188
|
if !(indexPath.row == 0) {
|
174
189
|
// 配列操作
|
175
190
|
let targetArray = arrayOfArray[indexPath.section]
|
@@ -197,24 +212,25 @@
|
|
197
212
|
// リロードしないとHeaderViewが表示されなくなる/なぜ?
|
198
213
|
testTableView.reloadData()
|
199
214
|
|
200
|
-
/* tableViewをリロードしない場合の呼び出し回数
|
215
|
+
/* tableViewをリロードしない場合の呼び出し回数/LongPress"FFFF"
|
216
|
+
CellLongPressed/addSectionHeaderView
|
201
|
-
|
217
|
+
numberOfSection
|
202
|
-
|
218
|
+
numberOfSection
|
203
|
-
|
219
|
+
generateSection
|
204
220
|
*/
|
205
221
|
|
206
|
-
/* tableViewをリロードした場合の呼び出し回数
|
222
|
+
/* tableViewをリロードした場合の呼び出し回数/LongPress"FFFF"
|
223
|
+
CellLongPressed/addSectionHeaderView
|
207
|
-
|
224
|
+
numberOfSection
|
208
|
-
|
225
|
+
numberOfSection
|
209
|
-
|
226
|
+
generateSection
|
210
|
-
|
227
|
+
numberOfSection
|
211
|
-
|
228
|
+
generateSection
|
212
|
-
|
229
|
+
generateSection
|
213
|
-
|
230
|
+
generateSection
|
214
231
|
*/
|
215
232
|
|
216
233
|
}
|
217
234
|
}
|
218
235
|
}
|
219
|
-
|
220
236
|
```
|
1
進捗反映
title
CHANGED
File without changes
|
body
CHANGED
@@ -125,12 +125,96 @@
|
|
125
125
|
```
|
126
126
|
|
127
127
|
方向性が間違っているのかもしれませんが、
|
128
|
-
`beginUpdates()`〜`endUpdates()`の内部で削除->挿入をすればよいのかと
|
128
|
+
`beginUpdates()`〜`endUpdates()`の内部で削除->挿入をすればよいのかと進めているのですが、
|
129
|
+
SectionHeaderをインサートするアニメーションがうまく動きません。
|
130
|
+
(SectionHeaderを削除するアニメーションは我慢できる程度には動かすことができました。)
|
129
131
|
|
132
|
+

|
133
|
+
|
130
134
|
```swift
|
131
|
-
|
135
|
+
// セクションヘッダーを取り除く処理
|
136
|
+
@IBAction func removeSectionBtnTapped(_ sender: UIButton) {
|
137
|
+
guard let targetSection = sender.superview?.superview?.tag else { return }
|
138
|
+
let preTargetSection = targetSection - 1
|
139
|
+
|
140
|
+
if !(targetSection == 0) {
|
141
|
+
|
142
|
+
// 配列操作
|
143
|
+
let targetSectionArray = arrayOfArray[targetSection]
|
144
|
+
arrayOfArray.remove(at: targetSection)
|
145
|
+
let preTargetSectionArray = arrayOfArray[preTargetSection]
|
146
|
+
arrayOfArray[preTargetSection] = preTargetSectionArray + targetSectionArray
|
147
|
+
|
148
|
+
// 挿入するインデックスパスの配列を作る
|
149
|
+
let insertIndexes: [IndexPath] =
|
150
|
+
(preTargetSectionArray.count ..< arrayOfArray[preTargetSection].count).map {[preTargetSection, $0]}
|
151
|
+
|
152
|
+
// tableViewを編集する
|
132
|
-
testTableView.beginUpdates()
|
153
|
+
testTableView.beginUpdates()
|
154
|
+
testTableView.deleteSections(IndexSet(integer: targetSection), with: .none)
|
133
|
-
testTableView.
|
155
|
+
testTableView.insertRows(at: insertIndexes, with: .fade)
|
134
|
-
testTableView.insertSections(indexSet, with: .automatic)
|
135
|
-
testTableView.endUpdates()
|
156
|
+
testTableView.endUpdates()
|
157
|
+
// リロードしないとHeaderViewが表示されなくなる/なぜ?
|
158
|
+
testTableView.reloadData()
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
// セクションヘッダーを追加する処理
|
163
|
+
@IBAction func addSectionHeaderView(_ sender: UILongPressGestureRecognizer) {
|
164
|
+
if(sender.state == UIGestureRecognizer.State.began) {
|
165
|
+
} else if (sender.state == UIGestureRecognizer.State.ended) {
|
166
|
+
|
167
|
+
let point = sender.location(in: testTableView)
|
168
|
+
guard let indexPath = testTableView.indexPathForRow(at: point) else { return }
|
169
|
+
|
170
|
+
|
171
|
+
print("addSectionHeaderView")
|
172
|
+
|
173
|
+
if !(indexPath.row == 0) {
|
174
|
+
// 配列操作
|
175
|
+
let targetArray = arrayOfArray[indexPath.section]
|
176
|
+
let firsrOfTargetArray = targetArray.prefix(indexPath.row)
|
177
|
+
let secondOfTargetArray = targetArray.dropFirst(indexPath.row)
|
178
|
+
arrayOfArray.remove(at: indexPath.section)
|
179
|
+
arrayOfArray.insert(firsrOfTargetArray.map{$0}, at: indexPath.section)
|
180
|
+
arrayOfArray.insert(secondOfTargetArray.map{$0}, at: indexPath.section + 1)
|
181
|
+
|
182
|
+
// 削除するインデックスパスの配列を作る
|
183
|
+
let deleteIndexes: [IndexPath] =
|
184
|
+
(indexPath.row ..< targetArray.count).map {[indexPath.section, $0]}
|
185
|
+
|
186
|
+
|
187
|
+
//TODO: -- ここがうまくいかない/アニメーションの組み合わせの考察 --
|
188
|
+
// tableView操作
|
189
|
+
testTableView.beginUpdates()
|
190
|
+
|
191
|
+
//testTableView.deleteSections(IndexSet(integer: indexPath.section), with: .none)
|
192
|
+
//testTableView.insertSections(IndexSet(integer: indexPath.section), with: .none)
|
193
|
+
|
194
|
+
testTableView.deleteRows(at: deleteIndexes, with: .none)
|
195
|
+
testTableView.insertSections(IndexSet(integer: indexPath.section + 1), with: .top)
|
196
|
+
testTableView.endUpdates()
|
197
|
+
// リロードしないとHeaderViewが表示されなくなる/なぜ?
|
198
|
+
testTableView.reloadData()
|
199
|
+
|
200
|
+
/* tableViewをリロードしない場合の呼び出し回数
|
201
|
+
numberOfSection
|
202
|
+
numberOfSection
|
203
|
+
generateSection
|
204
|
+
*/
|
205
|
+
|
206
|
+
/* tableViewをリロードした場合の呼び出し回数
|
207
|
+
numberOfSection
|
208
|
+
numberOfSection
|
209
|
+
generateSection
|
210
|
+
numberOfSection
|
211
|
+
generateSection
|
212
|
+
generateSection
|
213
|
+
generateSection
|
214
|
+
*/
|
215
|
+
|
216
|
+
}
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
136
220
|
```
|