質問編集履歴

6

訂正

2018/10/01 23:00

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -18,12 +18,6 @@
18
18
 
19
19
 
20
20
 
21
- ↓`debug`-`SlowAnimations`/`Section:2`(青い部分)がパっと表示される
22
-
23
- ![イメージ説明](756c9418a5e3a21b41e9cacc62e1861b.gif)
24
-
25
-
26
-
27
21
  ```swift
28
22
 
29
23
  import UIKit

5

ソースを編集

2018/10/01 23:00

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -26,6 +26,10 @@
26
26
 
27
27
  ```swift
28
28
 
29
+ import UIKit
30
+
31
+
32
+
29
33
  class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
30
34
 
31
35
 
@@ -46,6 +50,120 @@
46
50
 
47
51
 
48
52
 
53
+ // セクションヘッダーを追加する処理
54
+
55
+ @IBAction func addSectionHeaderView(_ sender: UILongPressGestureRecognizer) {
56
+
57
+ if(sender.state == UIGestureRecognizer.State.began) {
58
+
59
+ } else if (sender.state == UIGestureRecognizer.State.ended) {
60
+
61
+
62
+
63
+ let point = sender.location(in: testTableView)
64
+
65
+ guard let indexPath = testTableView.indexPathForRow(at: point) else { return }
66
+
67
+
68
+
69
+ print("CellLongPressed/addSectionHeaderView")
70
+
71
+
72
+
73
+ if !(indexPath.row == 0) {
74
+
75
+ // 配列操作
76
+
77
+ let targetArray = arrayOfArray[indexPath.section]
78
+
79
+ let firsrOfTargetArray = targetArray.prefix(indexPath.row)
80
+
81
+ let secondOfTargetArray = targetArray.dropFirst(indexPath.row)
82
+
83
+ arrayOfArray.remove(at: indexPath.section)
84
+
85
+ arrayOfArray.insert(firsrOfTargetArray.map{$0}, at: indexPath.section)
86
+
87
+ arrayOfArray.insert(secondOfTargetArray.map{$0}, at: indexPath.section + 1)
88
+
89
+
90
+
91
+ // 削除するインデックスパスの配列を作る
92
+
93
+ let deleteIndexes: [IndexPath] =
94
+
95
+ (indexPath.row ..< targetArray.count).map {[indexPath.section, $0]}
96
+
97
+
98
+
99
+ //TODO: -- ここがうまくいかない/アニメーションの組み合わせ? --
100
+
101
+ // tableView操作
102
+
103
+ testTableView.beginUpdates()
104
+
105
+
106
+
107
+ //testTableView.deleteSections(IndexSet(integer: indexPath.section), with: .none)
108
+
109
+ //testTableView.insertSections(IndexSet(integer: indexPath.section), with: .none)
110
+
111
+
112
+
113
+ testTableView.deleteRows(at: deleteIndexes, with: .fade)
114
+
115
+ testTableView.insertSections(IndexSet(integer: indexPath.section + 1), with: .none)
116
+
117
+ testTableView.endUpdates()
118
+
119
+ // リロードしないとHeaderViewが表示されなくなる/tableView(_: viewForHeaderInSection) -> UIView?が呼ばれない
120
+
121
+ testTableView.reloadData()
122
+
123
+
124
+
125
+ /* tableViewをリロードしない場合の呼び出し回数/LongPress"FFFF"
126
+
127
+ CellLongPressed/addSectionHeaderView
128
+
129
+ numberOfSection/ 4
130
+
131
+ numberOfSection/ 4
132
+
133
+ generateSection
134
+
135
+ */
136
+
137
+
138
+
139
+ /* tableViewをリロードした場合の呼び出し回数/LongPress"FFFF"
140
+
141
+ CellLongPressed/addSectionHeaderView
142
+
143
+ numberOfSection/ 4
144
+
145
+ numberOfSection/ 4
146
+
147
+ generateSection
148
+
149
+ numberOfSection/ 4
150
+
151
+ generateSection
152
+
153
+ generateSection
154
+
155
+ generateSection
156
+
157
+ */
158
+
159
+ }
160
+
161
+ }
162
+
163
+ }
164
+
165
+
166
+
49
167
  // セクションヘッダーを取り除く処理
50
168
 
51
169
  @IBAction func removeSectionBtnTapped(_ sender: UIButton) {
@@ -116,7 +234,7 @@
116
234
 
117
235
  generateSection
118
236
 
119
- */
237
+ */
120
238
 
121
239
 
122
240
 
@@ -128,7 +246,7 @@
128
246
 
129
247
  numberOfSection/ 3
130
248
 
131
- */
249
+ */
132
250
 
133
251
  }
134
252
 
@@ -136,120 +254,6 @@
136
254
 
137
255
 
138
256
 
139
- // セクションヘッダーを追加する処理
140
-
141
- @IBAction func addSectionHeaderView(_ sender: UILongPressGestureRecognizer) {
142
-
143
- if(sender.state == UIGestureRecognizer.State.began) {
144
-
145
- } else if (sender.state == UIGestureRecognizer.State.ended) {
146
-
147
-
148
-
149
- let point = sender.location(in: testTableView)
150
-
151
- guard let indexPath = testTableView.indexPathForRow(at: point) else { return }
152
-
153
-
154
-
155
- print("CellLongPressed/addSectionHeaderView")
156
-
157
-
158
-
159
- if !(indexPath.row == 0) {
160
-
161
- // 配列操作
162
-
163
- let targetArray = arrayOfArray[indexPath.section]
164
-
165
- let firsrOfTargetArray = targetArray.prefix(indexPath.row)
166
-
167
- let secondOfTargetArray = targetArray.dropFirst(indexPath.row)
168
-
169
- arrayOfArray.remove(at: indexPath.section)
170
-
171
- arrayOfArray.insert(firsrOfTargetArray.map{$0}, at: indexPath.section)
172
-
173
- arrayOfArray.insert(secondOfTargetArray.map{$0}, at: indexPath.section + 1)
174
-
175
-
176
-
177
- // 削除するインデックスパスの配列を作る
178
-
179
- let deleteIndexes: [IndexPath] =
180
-
181
- (indexPath.row ..< targetArray.count).map {[indexPath.section, $0]}
182
-
183
-
184
-
185
- //TODO: -- ここがうまくいかない/アニメーションの組み合わせ? --
186
-
187
- // tableView操作
188
-
189
- testTableView.beginUpdates()
190
-
191
-
192
-
193
- //testTableView.deleteSections(IndexSet(integer: indexPath.section), with: .none)
194
-
195
- //testTableView.insertSections(IndexSet(integer: indexPath.section), with: .none)
196
-
197
-
198
-
199
- testTableView.deleteRows(at: deleteIndexes, with: .fade)
200
-
201
- testTableView.insertSections(IndexSet(integer: indexPath.section + 1), with: .none)
202
-
203
- testTableView.endUpdates()
204
-
205
- // リロードしないとHeaderViewが表示されなくなる/tableView(_: viewForHeaderInSection) -> UIView?が呼ばれない
206
-
207
- testTableView.reloadData()
208
-
209
-
210
-
211
- /* tableViewをリロードしない場合の呼び出し回数/LongPress"FFFF"
212
-
213
- CellLongPressed/addSectionHeaderView
214
-
215
- numberOfSection/ 4
216
-
217
- numberOfSection/ 4
218
-
219
- generateSection
220
-
221
- */
222
-
223
-
224
-
225
- /* tableViewをリロードした場合の呼び出し回数/LongPress"FFFF"
226
-
227
- CellLongPressed/addSectionHeaderView
228
-
229
- numberOfSection/ 4
230
-
231
- numberOfSection/ 4
232
-
233
- generateSection
234
-
235
- numberOfSection/ 4
236
-
237
- generateSection
238
-
239
- generateSection
240
-
241
- generateSection
242
-
243
- */
244
-
245
- }
246
-
247
- }
248
-
249
- }
250
-
251
-
252
-
253
257
  //MARK: - UITableViewDataSource -
254
258
 
255
259
 

4

訂正

2018/10/01 08:24

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -12,13 +12,13 @@
12
12
 
13
13
 
14
14
 
15
- ↓`Section:2`がパっと表示される、なんとかフェードインとかスライドインみたくならないでしょうか?
15
+ ↓`Section:2`(青い部分)がパっと表示される、なんとかフェードインとかスライドインみたくならないでしょうか?
16
16
 
17
17
  ![イメージ説明](b9e1ae5f7fc0f338d7813f864d92f325.gif)
18
18
 
19
19
 
20
20
 
21
- ↓`debug`-`SlowAnimations`表示
21
+ ↓`debug`-`SlowAnimations`/`Section:2`(青い部分)がパっと表示される
22
22
 
23
23
  ![イメージ説明](756c9418a5e3a21b41e9cacc62e1861b.gif)
24
24
 

3

進捗を反映

2018/10/01 08:07

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -2,23 +2,25 @@
2
2
 
3
3
 
4
4
 
5
- `UITabelView`の既存セクションの分割、結合をアニメーション付きで行いたいのですが、どのようにすればできるでしょうか?
6
-
7
- 現状はデータもとの2次元配列をいじってから`UITableView`全体を`reloadData()`して実現しているのでアニメーションがかかりません。
8
-
9
-
10
-
11
- 下記のGifでセクションの挿入/削除を、青いSectionHeaderだけがフェードイン/フェードアウトするような感じでアニメーション付きで表現できたらと思い
5
+ `UITabelView`/`SectionHeaderView`の挿入/削除をアニメーション付きで表示しようとしているのですが`SectionHeaderView`(青い部分)の挿入だけ思ったようアニメーションがかかりせん
6
+
12
-
7
+ どこを見直せばいいでしょうか、また方向性が根本から間違っているのでしょうか?
13
-
14
-
8
+
9
+
10
+
15
- 動作は、ロングプレスしたセルの上に`SectionHeader`を挿入し、`SectionHeader`にあるボタンで該当`SectionHeader`を削除しています。
11
+ 動作は、ロングプレスしたセルの上に`SectionHeader`を挿入し、`SectionHeader`にあるボタンで該当`SectionHeader`を削除しています。
12
+
13
+
14
+
16
-
15
+ ↓`Section:2`がパっと表示される、なんとかフェードインとかスライドインみたくならないでしょうか?
17
-
18
-
16
+
19
- ![イメージ説明](e008a398a0c6bd788bbe158744ab9e31.gif)
17
+ ![イメージ説明](b9e1ae5f7fc0f338d7813f864d92f325.gif)
18
+
19
+
20
+
20
-
21
+ ↓`debug`-`SlowAnimations`表示
22
+
21
-
23
+ ![イメージ説明](756c9418a5e3a21b41e9cacc62e1861b.gif)
22
24
 
23
25
 
24
26
 
@@ -48,30 +50,86 @@
48
50
 
49
51
  @IBAction func removeSectionBtnTapped(_ sender: UIButton) {
50
52
 
51
- guard let numOfSection = sender.superview?.superview?.tag else { return }
53
+ guard let targetSection = sender.superview?.superview?.tag else { return }
54
+
52
-
55
+ let preTargetSection = targetSection - 1
56
+
57
+
58
+
53
- if !(numOfSection == 0) {
59
+ if !(targetSection == 0) {
60
+
61
+
62
+
54
-
63
+ print("removeSectionBtnTapped")
55
-
56
-
64
+
65
+
66
+
57
- // 挿入するsectionデータを成する
67
+ // 配列操
58
-
68
+
59
- let insertArray = arrayOfArray[numOfSection - 1] + arrayOfArray[numOfSection]
69
+ let targetSectionArray = arrayOfArray[targetSection]
60
-
61
-
62
-
70
+
63
- arrayOfArray.remove(at: numOfSection)
71
+ arrayOfArray.remove(at: targetSection)
64
-
72
+
65
- arrayOfArray.remove(at: numOfSection - 1)
73
+ let preTargetSectionArray = arrayOfArray[preTargetSection]
66
-
67
-
68
-
74
+
69
- arrayOfArray.insert(insertArray, at: numOfSection - 1)
75
+ arrayOfArray[preTargetSection] = preTargetSectionArray + targetSectionArray
76
+
77
+
78
+
70
-
79
+ // 挿入するインデックスパスの配列を作る
80
+
71
-
81
+ let insertIndexes: [IndexPath] =
82
+
83
+ (preTargetSectionArray.count ..< arrayOfArray[preTargetSection].count).map {[preTargetSection, $0]}
84
+
85
+
86
+
87
+ // tableView操作
88
+
89
+ testTableView.beginUpdates()
90
+
91
+ testTableView.deleteSections(IndexSet(integer: targetSection), with: .none)
92
+
93
+ testTableView.insertRows(at: insertIndexes, with: .fade)
94
+
95
+ testTableView.endUpdates()
96
+
97
+
98
+
99
+ // リロードしないとHeaderViewが表示されなくなる/tableView(_: viewForHeaderInSection) -> UIView?が呼ばれない
72
100
 
73
101
  testTableView.reloadData()
74
102
 
103
+
104
+
105
+ /* tableViewをリロードした場合の呼び出し回数/Tap"FFFF"
106
+
107
+ removeSectionBtnTapped
108
+
109
+ numberOfSection/ 3
110
+
111
+ numberOfSection/ 3
112
+
113
+ numberOfSection/ 3
114
+
115
+ generateSection
116
+
117
+ generateSection
118
+
119
+ */
120
+
121
+
122
+
123
+ /* tableViewをリロードしない場合の呼び出し回数/Tap"FFFF"
124
+
125
+ removeSectionBtnTapped
126
+
127
+ numberOfSection/ 3
128
+
129
+ numberOfSection/ 3
130
+
131
+ */
132
+
75
133
  }
76
134
 
77
135
  }
@@ -80,7 +138,7 @@
80
138
 
81
139
  // セクションヘッダーを追加する処理
82
140
 
83
- @IBAction func cellLongPressed(_ sender: UILongPressGestureRecognizer) {
141
+ @IBAction func addSectionHeaderView(_ sender: UILongPressGestureRecognizer) {
84
142
 
85
143
  if(sender.state == UIGestureRecognizer.State.began) {
86
144
 
@@ -94,28 +152,96 @@
94
152
 
95
153
 
96
154
 
155
+ print("CellLongPressed/addSectionHeaderView")
156
+
157
+
158
+
97
159
  if !(indexPath.row == 0) {
98
160
 
161
+ // 配列操作
162
+
99
163
  let targetArray = arrayOfArray[indexPath.section]
100
164
 
101
165
  let firsrOfTargetArray = targetArray.prefix(indexPath.row)
102
166
 
103
167
  let secondOfTargetArray = targetArray.dropFirst(indexPath.row)
104
168
 
105
-
106
-
107
169
  arrayOfArray.remove(at: indexPath.section)
108
170
 
109
-
110
-
111
- arrayOfArray.insert(secondOfTargetArray.map{$0}, at: indexPath.section)
112
-
113
171
  arrayOfArray.insert(firsrOfTargetArray.map{$0}, at: indexPath.section)
114
172
 
115
-
173
+ arrayOfArray.insert(secondOfTargetArray.map{$0}, at: indexPath.section + 1)
174
+
175
+
176
+
177
+ // 削除するインデックスパスの配列を作る
178
+
179
+ let deleteIndexes: [IndexPath] =
180
+
181
+ (indexPath.row ..< targetArray.count).map {[indexPath.section, $0]}
182
+
183
+
184
+
185
+ //TODO: -- ここがうまくいかない/アニメーションの組み合わせ? --
186
+
187
+ // tableView操作
188
+
189
+ testTableView.beginUpdates()
190
+
191
+
192
+
193
+ //testTableView.deleteSections(IndexSet(integer: indexPath.section), with: .none)
194
+
195
+ //testTableView.insertSections(IndexSet(integer: indexPath.section), with: .none)
196
+
197
+
198
+
199
+ testTableView.deleteRows(at: deleteIndexes, with: .fade)
200
+
201
+ testTableView.insertSections(IndexSet(integer: indexPath.section + 1), with: .none)
202
+
203
+ testTableView.endUpdates()
204
+
205
+ // リロードしないとHeaderViewが表示されなくなる/tableView(_: viewForHeaderInSection) -> UIView?が呼ばれない
116
206
 
117
207
  testTableView.reloadData()
118
208
 
209
+
210
+
211
+ /* tableViewをリロードしない場合の呼び出し回数/LongPress"FFFF"
212
+
213
+ CellLongPressed/addSectionHeaderView
214
+
215
+ numberOfSection/ 4
216
+
217
+ numberOfSection/ 4
218
+
219
+ generateSection
220
+
221
+ */
222
+
223
+
224
+
225
+ /* tableViewをリロードした場合の呼び出し回数/LongPress"FFFF"
226
+
227
+ CellLongPressed/addSectionHeaderView
228
+
229
+ numberOfSection/ 4
230
+
231
+ numberOfSection/ 4
232
+
233
+ generateSection
234
+
235
+ numberOfSection/ 4
236
+
237
+ generateSection
238
+
239
+ generateSection
240
+
241
+ generateSection
242
+
243
+ */
244
+
119
245
  }
120
246
 
121
247
  }
@@ -124,8 +250,6 @@
124
250
 
125
251
 
126
252
 
127
-
128
-
129
253
  //MARK: - UITableViewDataSource -
130
254
 
131
255
 
@@ -138,6 +262,12 @@
138
262
 
139
263
  func numberOfSections(in tableView: UITableView) -> Int {
140
264
 
265
+
266
+
267
+ print("numberOfSection/",arrayOfArray.count)
268
+
269
+
270
+
141
271
  return arrayOfArray.count
142
272
 
143
273
  }
@@ -148,6 +278,12 @@
148
278
 
149
279
  func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
150
280
 
281
+
282
+
283
+ print("generateSection")
284
+
285
+
286
+
151
287
  let sectionHeaderView = testTableView.dequeueReusableCell(withIdentifier: "Section") as! SectionHeaderCell
152
288
 
153
289
 
@@ -196,9 +332,13 @@
196
332
 
197
333
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
198
334
 
199
- let cell = testTableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
335
+ let cell = testTableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CustomCell
200
-
336
+
201
- cell.textLabel?.text = arrayOfArray[indexPath.section][indexPath.row]
337
+ let cellLabelStr = arrayOfArray[indexPath.section][indexPath.row]
338
+
339
+
340
+
341
+ cell.setValueToCell(cellLabelStr: cellLabelStr)
202
342
 
203
343
 
204
344
 
@@ -242,230 +382,6 @@
242
382
 
243
383
  }
244
384
 
385
+
386
+
245
387
  ```
246
-
247
-
248
-
249
- 方向性が間違っているのかもしれませんが、
250
-
251
- `beginUpdates()`〜`endUpdates()`の内部で削除->挿入をすればよいのかと進めているのですが、
252
-
253
- SectionHeaderをインサートするアニメーションがうまく動きません。
254
-
255
- (SectionHeaderを削除するアニメーションは我慢できる程度には動かすことができました。)
256
-
257
-
258
-
259
- ![イメージ説明](17b93ba12ae8613a6a3b9218d41213a4.gif)
260
-
261
-
262
-
263
- ```swift
264
-
265
- // セクションヘッダーを取り除く処理
266
-
267
- @IBAction func removeSectionBtnTapped(_ sender: UIButton) {
268
-
269
- guard let targetSection = sender.superview?.superview?.tag else { return }
270
-
271
- let preTargetSection = targetSection - 1
272
-
273
-
274
-
275
- if !(targetSection == 0) {
276
-
277
-
278
-
279
- print("removeSectionBtnTapped")
280
-
281
-
282
-
283
- // 配列操作
284
-
285
- let targetSectionArray = arrayOfArray[targetSection]
286
-
287
- arrayOfArray.remove(at: targetSection)
288
-
289
- let preTargetSectionArray = arrayOfArray[preTargetSection]
290
-
291
- arrayOfArray[preTargetSection] = preTargetSectionArray + targetSectionArray
292
-
293
-
294
-
295
- // 挿入するインデックスパスの配列を作る
296
-
297
- let insertIndexes: [IndexPath] =
298
-
299
- (preTargetSectionArray.count ..< arrayOfArray[preTargetSection].count).map {[preTargetSection, $0]}
300
-
301
-
302
-
303
- // tableViewを編集する
304
-
305
- testTableView.beginUpdates()
306
-
307
- testTableView.deleteSections(IndexSet(integer: targetSection), with: .none)
308
-
309
- testTableView.insertRows(at: insertIndexes, with: .fade)
310
-
311
- testTableView.endUpdates()
312
-
313
- // リロードしないとHeaderViewが表示されなくなる/なぜ?
314
-
315
- testTableView.reloadData()
316
-
317
-
318
-
319
- /* tableViewをリロードした場合の呼び出し回数/Tap"FFFF"
320
-
321
- removeSectionBtnTapped
322
-
323
- numberOfSection
324
-
325
- numberOfSection
326
-
327
- numberOfSection
328
-
329
- generateSection
330
-
331
- generateSection
332
-
333
- */
334
-
335
-
336
-
337
- /* tableViewをリロードしない場合の呼び出し回数/Tap"FFFF"
338
-
339
- removeSectionBtnTapped
340
-
341
- numberOfSection
342
-
343
- numberOfSection
344
-
345
- */
346
-
347
-
348
-
349
- }
350
-
351
- }
352
-
353
-
354
-
355
- // セクションヘッダーを追加する処理
356
-
357
- @IBAction func addSectionHeaderView(_ sender: UILongPressGestureRecognizer) {
358
-
359
- if(sender.state == UIGestureRecognizer.State.began) {
360
-
361
- } else if (sender.state == UIGestureRecognizer.State.ended) {
362
-
363
-
364
-
365
- let point = sender.location(in: testTableView)
366
-
367
- guard let indexPath = testTableView.indexPathForRow(at: point) else { return }
368
-
369
-
370
-
371
- print("CellLongPressed/addSectionHeaderView")
372
-
373
-
374
-
375
- if !(indexPath.row == 0) {
376
-
377
- // 配列操作
378
-
379
- let targetArray = arrayOfArray[indexPath.section]
380
-
381
- let firsrOfTargetArray = targetArray.prefix(indexPath.row)
382
-
383
- let secondOfTargetArray = targetArray.dropFirst(indexPath.row)
384
-
385
- arrayOfArray.remove(at: indexPath.section)
386
-
387
- arrayOfArray.insert(firsrOfTargetArray.map{$0}, at: indexPath.section)
388
-
389
- arrayOfArray.insert(secondOfTargetArray.map{$0}, at: indexPath.section + 1)
390
-
391
-
392
-
393
- // 削除するインデックスパスの配列を作る
394
-
395
- let deleteIndexes: [IndexPath] =
396
-
397
- (indexPath.row ..< targetArray.count).map {[indexPath.section, $0]}
398
-
399
-
400
-
401
-
402
-
403
- //TODO: -- ここがうまくいかない/アニメーションの組み合わせの考察 --
404
-
405
- // tableView操作
406
-
407
- testTableView.beginUpdates()
408
-
409
-
410
-
411
- //testTableView.deleteSections(IndexSet(integer: indexPath.section), with: .none)
412
-
413
- //testTableView.insertSections(IndexSet(integer: indexPath.section), with: .none)
414
-
415
-
416
-
417
- testTableView.deleteRows(at: deleteIndexes, with: .none)
418
-
419
- testTableView.insertSections(IndexSet(integer: indexPath.section + 1), with: .top)
420
-
421
- testTableView.endUpdates()
422
-
423
- // リロードしないとHeaderViewが表示されなくなる/なぜ?
424
-
425
- testTableView.reloadData()
426
-
427
-
428
-
429
- /* tableViewをリロードしない場合の呼び出し回数/LongPress"FFFF"
430
-
431
- CellLongPressed/addSectionHeaderView
432
-
433
- numberOfSection
434
-
435
- numberOfSection
436
-
437
- generateSection
438
-
439
- */
440
-
441
-
442
-
443
- /* tableViewをリロードした場合の呼び出し回数/LongPress"FFFF"
444
-
445
- CellLongPressed/addSectionHeaderView
446
-
447
- numberOfSection
448
-
449
- numberOfSection
450
-
451
- generateSection
452
-
453
- numberOfSection
454
-
455
- generateSection
456
-
457
- generateSection
458
-
459
- generateSection
460
-
461
- */
462
-
463
-
464
-
465
- }
466
-
467
- }
468
-
469
- }
470
-
471
- ```

2

訂正

2018/10/01 08:05

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -38,10 +38,6 @@
38
38
 
39
39
 
40
40
 
41
- var sectionNumberArray: [Int] = [1,2]
42
-
43
-
44
-
45
41
  //MARK: -- Outlets --
46
42
 
47
43
  @IBOutlet weak var testTableView: UITableView!
@@ -280,6 +276,10 @@
280
276
 
281
277
 
282
278
 
279
+ print("removeSectionBtnTapped")
280
+
281
+
282
+
283
283
  // 配列操作
284
284
 
285
285
  let targetSectionArray = arrayOfArray[targetSection]
@@ -314,6 +314,38 @@
314
314
 
315
315
  testTableView.reloadData()
316
316
 
317
+
318
+
319
+ /* tableViewをリロードした場合の呼び出し回数/Tap"FFFF"
320
+
321
+ removeSectionBtnTapped
322
+
323
+ numberOfSection
324
+
325
+ numberOfSection
326
+
327
+ numberOfSection
328
+
329
+ generateSection
330
+
331
+ generateSection
332
+
333
+ */
334
+
335
+
336
+
337
+ /* tableViewをリロードしない場合の呼び出し回数/Tap"FFFF"
338
+
339
+ removeSectionBtnTapped
340
+
341
+ numberOfSection
342
+
343
+ numberOfSection
344
+
345
+ */
346
+
347
+
348
+
317
349
  }
318
350
 
319
351
  }
@@ -336,9 +368,7 @@
336
368
 
337
369
 
338
370
 
339
-
340
-
341
- print("addSectionHeaderView")
371
+ print("CellLongPressed/addSectionHeaderView")
342
372
 
343
373
 
344
374
 
@@ -396,33 +426,37 @@
396
426
 
397
427
 
398
428
 
399
- /* tableViewをリロードしない場合の呼び出し回数
429
+ /* tableViewをリロードしない場合の呼び出し回数/LongPress"FFFF"
430
+
400
-
431
+ CellLongPressed/addSectionHeaderView
432
+
401
- numberOfSection
433
+ numberOfSection
402
-
434
+
403
- numberOfSection
435
+ numberOfSection
404
-
436
+
405
- generateSection
437
+ generateSection
406
438
 
407
439
  */
408
440
 
409
441
 
410
442
 
411
- /* tableViewをリロードした場合の呼び出し回数
443
+ /* tableViewをリロードした場合の呼び出し回数/LongPress"FFFF"
444
+
412
-
445
+ CellLongPressed/addSectionHeaderView
446
+
413
- numberOfSection
447
+ numberOfSection
414
-
448
+
415
- numberOfSection
449
+ numberOfSection
416
-
450
+
417
- generateSection
451
+ generateSection
418
-
452
+
419
- numberOfSection
453
+ numberOfSection
420
-
454
+
421
- generateSection
455
+ generateSection
422
-
456
+
423
- generateSection
457
+ generateSection
424
-
458
+
425
- generateSection
459
+ generateSection
426
460
 
427
461
  */
428
462
 
@@ -434,6 +468,4 @@
434
468
 
435
469
  }
436
470
 
437
-
438
-
439
471
  ```

1

進捗反映

2018/09/30 22:22

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -252,20 +252,188 @@
252
252
 
253
253
  方向性が間違っているのかもしれませんが、
254
254
 
255
- `beginUpdates()`〜`endUpdates()`の内部で削除->挿入をすればよいのかと思っているのですが、`insertSections`の`indexSet`のイメージがピンとこず停滞しています。
255
+ `beginUpdates()`〜`endUpdates()`の内部で削除->挿入をすればよいのかと進めているのですが、
256
+
257
+ SectionHeaderをインサートするアニメーションがうまく動きません。
258
+
259
+ (SectionHeaderを削除するアニメーションは我慢できる程度には動かすことができました。)
260
+
261
+
262
+
263
+ ![イメージ説明](17b93ba12ae8613a6a3b9218d41213a4.gif)
256
264
 
257
265
 
258
266
 
259
267
  ```swift
260
268
 
261
-
269
+ // セクションヘッダーを取り除く処理
270
+
262
-
271
+ @IBAction func removeSectionBtnTapped(_ sender: UIButton) {
272
+
273
+ guard let targetSection = sender.superview?.superview?.tag else { return }
274
+
275
+ let preTargetSection = targetSection - 1
276
+
277
+
278
+
279
+ if !(targetSection == 0) {
280
+
281
+
282
+
283
+ // 配列操作
284
+
285
+ let targetSectionArray = arrayOfArray[targetSection]
286
+
287
+ arrayOfArray.remove(at: targetSection)
288
+
289
+ let preTargetSectionArray = arrayOfArray[preTargetSection]
290
+
291
+ arrayOfArray[preTargetSection] = preTargetSectionArray + targetSectionArray
292
+
293
+
294
+
295
+ // 挿入するインデックスパスの配列を作る
296
+
297
+ let insertIndexes: [IndexPath] =
298
+
299
+ (preTargetSectionArray.count ..< arrayOfArray[preTargetSection].count).map {[preTargetSection, $0]}
300
+
301
+
302
+
303
+ // tableViewを編集する
304
+
263
- testTableView.beginUpdates()
305
+ testTableView.beginUpdates()
306
+
264
-
307
+ testTableView.deleteSections(IndexSet(integer: targetSection), with: .none)
308
+
265
- testTableView.deleteRows(at: indexes, with: .automatic)
309
+ testTableView.insertRows(at: insertIndexes, with: .fade)
266
-
267
- testTableView.insertSections(indexSet, with: .automatic)
310
+
268
-
269
- testTableView.endUpdates()
311
+ testTableView.endUpdates()
312
+
313
+ // リロードしないとHeaderViewが表示されなくなる/なぜ?
314
+
315
+ testTableView.reloadData()
316
+
317
+ }
318
+
319
+ }
320
+
321
+
322
+
323
+ // セクションヘッダーを追加する処理
324
+
325
+ @IBAction func addSectionHeaderView(_ sender: UILongPressGestureRecognizer) {
326
+
327
+ if(sender.state == UIGestureRecognizer.State.began) {
328
+
329
+ } else if (sender.state == UIGestureRecognizer.State.ended) {
330
+
331
+
332
+
333
+ let point = sender.location(in: testTableView)
334
+
335
+ guard let indexPath = testTableView.indexPathForRow(at: point) else { return }
336
+
337
+
338
+
339
+
340
+
341
+ print("addSectionHeaderView")
342
+
343
+
344
+
345
+ if !(indexPath.row == 0) {
346
+
347
+ // 配列操作
348
+
349
+ let targetArray = arrayOfArray[indexPath.section]
350
+
351
+ let firsrOfTargetArray = targetArray.prefix(indexPath.row)
352
+
353
+ let secondOfTargetArray = targetArray.dropFirst(indexPath.row)
354
+
355
+ arrayOfArray.remove(at: indexPath.section)
356
+
357
+ arrayOfArray.insert(firsrOfTargetArray.map{$0}, at: indexPath.section)
358
+
359
+ arrayOfArray.insert(secondOfTargetArray.map{$0}, at: indexPath.section + 1)
360
+
361
+
362
+
363
+ // 削除するインデックスパスの配列を作る
364
+
365
+ let deleteIndexes: [IndexPath] =
366
+
367
+ (indexPath.row ..< targetArray.count).map {[indexPath.section, $0]}
368
+
369
+
370
+
371
+
372
+
373
+ //TODO: -- ここがうまくいかない/アニメーションの組み合わせの考察 --
374
+
375
+ // tableView操作
376
+
377
+ testTableView.beginUpdates()
378
+
379
+
380
+
381
+ //testTableView.deleteSections(IndexSet(integer: indexPath.section), with: .none)
382
+
383
+ //testTableView.insertSections(IndexSet(integer: indexPath.section), with: .none)
384
+
385
+
386
+
387
+ testTableView.deleteRows(at: deleteIndexes, with: .none)
388
+
389
+ testTableView.insertSections(IndexSet(integer: indexPath.section + 1), with: .top)
390
+
391
+ testTableView.endUpdates()
392
+
393
+ // リロードしないとHeaderViewが表示されなくなる/なぜ?
394
+
395
+ testTableView.reloadData()
396
+
397
+
398
+
399
+ /* tableViewをリロードしない場合の呼び出し回数
400
+
401
+ numberOfSection
402
+
403
+ numberOfSection
404
+
405
+ generateSection
406
+
407
+ */
408
+
409
+
410
+
411
+ /* tableViewをリロードした場合の呼び出し回数
412
+
413
+ numberOfSection
414
+
415
+ numberOfSection
416
+
417
+ generateSection
418
+
419
+ numberOfSection
420
+
421
+ generateSection
422
+
423
+ generateSection
424
+
425
+ generateSection
426
+
427
+ */
428
+
429
+
430
+
431
+ }
432
+
433
+ }
434
+
435
+ }
436
+
437
+
270
438
 
271
439
  ```