質問編集履歴

5

コードの変更

2017/10/28 13:19

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,4 @@
1
- ![イメージ説明](6a91dc1908cdefea46c70606d8607669.png)**やりたいこと**
1
+ ![イメージ説明](6a91dc1908cdefea46c70606d8607669.png)
2
-
3
- 各cellのタイトルだけを左から右にスワイプして削除できるようにしたいです。
4
2
 
5
3
 
6
4
 
@@ -50,9 +48,9 @@
50
48
 
51
49
  for name in initialItems {
52
50
 
53
- kei.append(Item(name: name, deletable: false,completable: false))
54
-
55
- kei.append(Item(name: name, deletable: false, completable: false))
51
+ kei.append(Item(name: name, deletable: false,deletecell: false, completable: false,cellcolor: false))
52
+
53
+ kei.append(Item(name: name, deletable: false, deletecell: false, completable: false,cellcolor: false))
56
54
 
57
55
  }
58
56
 
@@ -96,11 +94,11 @@
96
94
 
97
95
  //self.items.append(Item(name: textField.text!))
98
96
 
99
- self.kei.append(Item(name: textField.text!,deletable: false,completable: false))
97
+ self.kei.append(Item(name: textField.text!,deletable: true, deletecell: true,completable: false, cellcolor: true))
100
98
 
101
99
  }
102
100
 
103
- self.kei.append(Item(name: "cell 追加 ボタン",deletable: true,completable: true))
101
+ self.kei.append(Item(name: textField.text!,deletable: true, deletecell: true,completable: false, cellcolor: true))
104
102
 
105
103
  self.mytableView.reloadData()
106
104
 
@@ -276,7 +274,7 @@
276
274
 
277
275
  for textField in textFields {
278
276
 
279
- self.kei.insert(Item(name: textField.text!,deletable: false,completable: false), at: indexPath.row)
277
+ self.kei[indexPath.row] = (Item(name: textField.text!,deletable: false, deletecell: true,completable: false, cellcolor: false)), at: indexPath.row)
280
278
 
281
279
  }
282
280
 
@@ -386,7 +384,7 @@
386
384
 
387
385
  for textField in textFields {
388
386
 
389
- self.kei[indexPath.row] = (Item(name: textField.text!,deletable: true,completable :true))
387
+ self.kei[indexPath.row] = (Item(name: textField.text!,deletable: false, deletecell: true,completable: false, cellcolor: false))
390
388
 
391
389
  //self.kei.append(textField.text!)
392
390
 
@@ -532,7 +530,7 @@
532
530
 
533
531
  for textField in textFields {
534
532
 
535
- self.kei[indexPath.row] = (Item(name: textField.text!,deletable: true,completable: true))
533
+ self.kei[indexPath.row] = (Item(name: textField.text!,deletable: false, deletecell: true,completable: false, cellcolor: false))
536
534
 
537
535
 
538
536
 

4

画像の追加

2017/10/28 13:19

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- **やりたいこと**
1
+ ![イメージ説明](6a91dc1908cdefea46c70606d8607669.png)**やりたいこと**
2
2
 
3
3
  各cellのタイトルだけを左から右にスワイプして削除できるようにしたいです。
4
4
 

3

コードの変更

2017/10/27 01:55

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,14 @@
1
+ **やりたいこと**
2
+
3
+ 各cellのタイトルだけを左から右にスワイプして削除できるようにしたいです。
4
+
5
+
6
+
7
+ **出来たことと今のコード**
8
+
9
+
10
+
1
- ```swift
11
+ ```ここに言語を入力
2
12
 
3
13
  import UIKit
4
14
 
@@ -10,15 +20,21 @@
10
20
 
11
21
  @IBOutlet weak var mytableView: UITableView!
12
22
 
23
+
24
+
25
+
26
+
13
-
27
+ let initialItems: [String] = []
28
+
29
+
14
30
 
15
31
  var kei: [Item] = Array()
16
32
 
17
33
 
18
34
 
19
-
20
-
21
-
35
+
36
+
37
+
22
38
 
23
39
  override func viewDidLoad() {
24
40
 
@@ -30,51 +46,65 @@
30
46
 
31
47
  mytableView.dataSource = self
32
48
 
49
+
50
+
33
-
51
+ for name in initialItems {
52
+
53
+ kei.append(Item(name: name, deletable: false,completable: false))
54
+
55
+ kei.append(Item(name: name, deletable: false, completable: false))
56
+
57
+ }
58
+
59
+
34
60
 
35
61
  }
36
62
 
37
-
38
-
39
-
63
+
64
+
65
+
66
+
67
+
40
68
 
41
69
  @IBAction func addbtr(_ sender: Any) {
42
70
 
43
-
44
-
45
-
71
+
72
+
73
+
46
74
 
47
75
  let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
48
76
 
49
-
50
-
51
-
77
+
78
+
79
+
52
80
 
53
81
  let okAction = UIAlertAction(title: "OK", style: .default, handler: {
54
82
 
55
83
  (action:UIAlertAction!) -> Void in
56
84
 
57
-
58
-
59
-
85
+
86
+
87
+
60
88
 
61
89
  if let textFields = alert.textFields {
62
90
 
63
-
91
+
92
+
93
+
64
94
 
65
95
  for textField in textFields {
66
96
 
67
- self.kei.append(Item(name: textField.text!))
97
+ //self.items.append(Item(name: textField.text!))
68
-
98
+
69
- self.kei.append(Item(name: "cell 追加 ボタン"))
99
+ self.kei.append(Item(name: textField.text!,deletable: false,completable: false))
70
-
71
- //(Item(name: textField.text!)
72
100
 
73
101
  }
74
102
 
103
+ self.kei.append(Item(name: "cell 追加 ボタン",deletable: true,completable: true))
104
+
75
105
  self.mytableView.reloadData()
76
106
 
77
-
107
+
78
108
 
79
109
  }
80
110
 
@@ -82,17 +112,17 @@
82
112
 
83
113
  alert.addAction(okAction)
84
114
 
85
-
86
-
87
-
115
+
116
+
117
+
88
118
 
89
119
  let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
90
120
 
91
121
  alert.addAction(cancelAction)
92
122
 
93
-
94
-
95
-
123
+
124
+
125
+
96
126
 
97
127
  alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
98
128
 
@@ -100,21 +130,19 @@
100
130
 
101
131
  })
102
132
 
103
-
104
-
105
-
133
+
134
+
135
+
106
136
 
107
137
  alert.view.setNeedsLayout()
108
138
 
109
-
110
-
111
139
  self.present(alert, animated: true, completion: nil)
112
140
 
113
-
114
-
141
+
142
+
115
- }
143
+ }
116
-
117
-
144
+
145
+
118
146
 
119
147
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
120
148
 
@@ -122,13 +150,13 @@
122
150
 
123
151
  }
124
152
 
125
-
126
-
127
-
153
+
154
+
155
+
128
156
 
129
157
  func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
130
158
 
131
-
159
+
132
160
 
133
161
  switch indexPath.row {
134
162
 
@@ -136,6 +164,8 @@
136
164
 
137
165
  return indexPath;
138
166
 
167
+
168
+
139
169
  default:
140
170
 
141
171
  return nil;
@@ -144,7 +174,7 @@
144
174
 
145
175
  }
146
176
 
147
-
177
+
148
178
 
149
179
  func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
150
180
 
@@ -152,65 +182,67 @@
152
182
 
153
183
  }
154
184
 
155
-
185
+
156
186
 
157
187
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
158
188
 
159
-
189
+
160
190
 
161
191
  let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
162
192
 
163
-
193
+ //追加した内容に対して
164
194
 
165
195
  let item = kei[indexPath.row]
166
196
 
167
197
  cell.textLabel?.text = item.name
168
198
 
169
- cell.textLabel?.textColor = UIColor.red
199
+
170
-
171
- cell.backgroundColor = UIColor.black
172
-
173
-
174
-
175
-
176
200
 
177
201
 
178
202
 
179
203
  if cell.textLabel?.text != "cell 追加 ボタン" {
180
204
 
181
-      cell.accessoryType = item.complete ? .checkmark : .none
205
+ cell.accessoryType = item.complete ? .checkmark : .none
182
206
 
183
207
  cell.textLabel?.textColor = UIColor.black
184
208
 
185
209
  cell.backgroundColor = UIColor.yellow
186
210
 
187
-
211
+ }else {
212
+
213
+ cell.accessoryType = .none
214
+
215
+ cell.textLabel?.textColor = UIColor.red
216
+
217
+ cell.backgroundColor = UIColor.black
218
+
219
+ }
220
+
221
+
222
+
223
+ if indexPath.row == 0 {
224
+
225
+ cell.textLabel?.textColor = UIColor.black
226
+
227
+ cell.backgroundColor = UIColor.white
228
+
229
+ cell.accessoryType = .none
188
230
 
189
231
  }
190
232
 
191
- if indexPath.row == 0 {
233
+
192
-
193
- cell.textLabel?.textColor = UIColor.black
194
-
195
- cell.backgroundColor = UIColor.white
196
-
197
- }
198
-
199
-
200
234
 
201
235
  return cell
202
236
 
203
237
  }
204
238
 
205
-
206
-
207
239
  func tableView(_ tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) -> IndexPath? {
208
240
 
209
241
 
210
242
 
211
243
  let cell = tableView.cellForRow(at: indexPath)
212
244
 
213
-
245
+
214
246
 
215
247
  if cell?.textLabel?.text != "cell 追加 ボタン"{
216
248
 
@@ -218,39 +250,39 @@
218
250
 
219
251
  tableView.deselectRow(at: indexPath, animated: true)
220
252
 
253
+ tableView.reloadRows(at: [indexPath], with: .none)
254
+
221
255
  return nil
222
256
 
223
257
  }else {
224
258
 
225
259
  let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
226
260
 
227
-
261
+
262
+
263
+
228
264
 
229
265
  let okAction = UIAlertAction(title: "OK", style: .default, handler: {
230
266
 
231
267
  (action:UIAlertAction!) -> Void in
232
268
 
233
-
234
-
235
-
269
+
236
270
 
237
271
  if let textFields = alert.textFields {
238
272
 
239
-
240
-
241
-
273
+
274
+
275
+
242
276
 
243
277
  for textField in textFields {
244
278
 
245
- self.kei.insert(Item(name: textField.text!), at: indexPath.row)
279
+ self.kei.insert(Item(name: textField.text!,deletable: false,completable: false), at: indexPath.row)
246
-
247
-
248
280
 
249
281
  }
250
282
 
251
283
  self.mytableView.reloadData()
252
284
 
253
-
285
+
254
286
 
255
287
  }
256
288
 
@@ -258,13 +290,17 @@
258
290
 
259
291
  alert.addAction(okAction)
260
292
 
261
-
293
+
294
+
295
+
262
296
 
263
297
  let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
264
298
 
265
299
  alert.addAction(cancelAction)
266
300
 
267
-
301
+
302
+
303
+
268
304
 
269
305
  alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
270
306
 
@@ -272,33 +308,29 @@
272
308
 
273
309
  })
274
310
 
275
-
276
-
277
-
278
-
311
+
312
+
313
+
314
+
279
- alert.view.setNeedsLayout()
315
+ alert.view.setNeedsLayout() /
280
-
281
-
282
-
283
-
284
316
 
285
317
  self.present(alert, animated: true, completion: nil)
286
318
 
287
-
319
+
288
320
 
289
321
  return indexPath
290
322
 
291
323
  }
292
324
 
293
-
325
+
294
326
 
295
327
  }
296
328
 
297
-
298
-
299
-
300
-
301
-
329
+
330
+
331
+
332
+
333
+
302
334
 
303
335
  func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
304
336
 
@@ -312,212 +344,256 @@
312
344
 
313
345
  }
314
346
 
315
-
316
-
347
+
348
+
317
- func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
349
+ //func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
350
+
318
-
351
+ func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
319
-
320
-
352
+
321
- let delete = UITableViewRowAction(style: .normal, title: "削除") {ation, index in
353
+ let delete = UIContextualAction(style: .normal,title: "削除", handler: { (action: UIContextualAction, view: UIView, success :(Bool) -> Void) in
322
-
354
+
323
- self.kei.remove(at: (indexPath.row))
355
+ self.kei.remove(at: indexPath.row)
324
356
 
325
357
  tableView.deleteRows(at: [indexPath], with: .fade)
326
358
 
359
+ success(true)
360
+
361
+ })
362
+
363
+
364
+
365
+ let edit = UIContextualAction(style: .normal,title: "編集", handler: { (action: UIContextualAction, view: UIView, success :(Bool) -> Void) in
366
+
367
+
368
+
369
+ let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
370
+
371
+
372
+
373
+
374
+
375
+ let okAction = UIAlertAction(title: "OK", style: .default, handler: {
376
+
377
+ (action:UIAlertAction!) -> Void in
378
+
379
+
380
+
381
+
382
+
383
+ if let textFields = alert.textFields {
384
+
385
+
386
+
387
+ for textField in textFields {
388
+
389
+ self.kei[indexPath.row] = (Item(name: textField.text!,deletable: true,completable :true))
390
+
391
+ //self.kei.append(textField.text!)
392
+
327
- }
393
+ }
394
+
395
+ self.mytableView.reloadData()
396
+
397
+
398
+
399
+ }
400
+
401
+ })
402
+
403
+ alert.addAction(okAction)
404
+
405
+
406
+
407
+
408
+
409
+ let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
410
+
411
+ alert.addAction(cancelAction)
412
+
413
+
414
+
415
+
416
+
417
+ alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
418
+
419
+ textField.placeholder = "テキスト"
420
+
421
+ })
422
+
423
+
424
+
425
+
426
+
427
+ alert.view.setNeedsLayout()
428
+
429
+ self.present(alert, animated: true, completion: nil)
430
+
431
+ print("edit")
432
+
433
+
434
+
435
+ success(true)
436
+
437
+ })
438
+
439
+
328
440
 
329
441
  delete.backgroundColor = .red
330
442
 
331
-
332
-
333
- let edit = UITableViewRowAction(style: .normal, title: "編集") { action, index in
334
-
335
-
336
-
337
- let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
338
-
339
-
340
-
341
-
342
-
343
- let okAction = UIAlertAction(title: "OK", style: .default, handler: {
344
-
345
- (action:UIAlertAction!) -> Void in
346
-
347
-
348
-
349
-
350
-
351
- if let textFields = alert.textFields {
352
-
353
-
354
-
355
-
356
-
357
- for textField in textFields {
358
-
359
- self.kei[indexPath.row] = (Item(name: textField.text!))
360
-
361
- //self.kei.append(textField.text!)
443
+ edit.backgroundColor = .blue
444
+
445
+
446
+
447
+ let swipeAction = UISwipeActionsConfiguration(actions: [delete])
448
+
449
+ swipeAction.performsFirstActionWithFullSwipe = false
450
+
451
+
452
+
453
+ return UISwipeActionsConfiguration(actions: [delete,edit])
454
+
455
+ }
456
+
457
+
458
+
459
+
460
+
461
+
462
+
463
+ // trueを返すことでCellのアクションを許可しています
464
+
465
+ func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
466
+
467
+
468
+
469
+ if kei.count > (indexPath.row + 1) {
470
+
471
+ return true
472
+
473
+ }else{
474
+
475
+ return false
476
+
477
+ }
478
+
479
+ }
480
+
481
+
482
+
483
+ override func didReceiveMemoryWarning() {
484
+
485
+ super.didReceiveMemoryWarning()
486
+
487
+
488
+
489
+ }
490
+
491
+ //左から右へスワイプ
492
+
493
+ func tableView(_ tableView: UITableView,
494
+
495
+ leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
496
+
497
+
498
+
499
+ let delete = UIContextualAction(style: .normal,title: "削除", handler: { (action: UIContextualAction, view: UIView, success :(Bool) -> Void) in
500
+
501
+ self.kei.remove(at: indexPath.row)
502
+
503
+ tableView.deleteRows(at: [indexPath], with: .fade)
504
+
505
+ success(true)
506
+
507
+ })
508
+
509
+
510
+
511
+ let edit = UIContextualAction(style: .normal,title: "編集", handler: { (action: UIContextualAction, view: UIView, success :(Bool) -> Void) in
512
+
513
+
514
+
515
+ let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
516
+
517
+
518
+
519
+ // OKボタンの設定
520
+
521
+ let okAction = UIAlertAction(title: "OK", style: .default, handler: {
522
+
523
+ (action:UIAlertAction!) -> Void in
524
+
525
+
526
+
527
+ // OKを押した時入力されていたテキストを表示
528
+
529
+ if let textFields = alert.textFields {
530
+
531
+
532
+
533
+ for textField in textFields {
534
+
535
+ self.kei[indexPath.row] = (Item(name: textField.text!,deletable: true,completable: true))
536
+
537
+
538
+
539
+ }
540
+
541
+ self.mytableView.reloadData()
542
+
543
+
362
544
 
363
545
  }
364
546
 
365
- self.mytableView.reloadData()
366
-
367
-
368
-
369
- }
547
+ })
548
+
549
+ alert.addAction(okAction)
550
+
551
+
552
+
553
+ let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
554
+
555
+ alert.addAction(cancelAction)
556
+
557
+
558
+
559
+
560
+
561
+ alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
562
+
563
+ textField.placeholder = "テキスト"
564
+
565
+ })
566
+
567
+ alert.view.setNeedsLayout()
568
+
569
+ self.present(alert, animated: true, completion: nil)
570
+
571
+ print("edit")
572
+
573
+
574
+
575
+ success(true)
370
576
 
371
577
  })
372
578
 
579
+
580
+
373
- alert.addAction(okAction)
581
+ delete.backgroundColor = .orange
374
-
375
-
376
-
377
-
378
-
379
- let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
582
+
380
-
381
- alert.addAction(cancelAction)
583
+ edit.backgroundColor = .blue
382
-
383
-
384
-
385
-
386
-
584
+
585
+
586
+
387
- alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
587
+ return UISwipeActionsConfiguration(actions: [delete,edit])
388
-
389
- textField.placeholder = "テキスト"
588
+
390
-
391
- })
589
+
392
-
393
-
394
-
395
-
396
-
397
- alert.view.setNeedsLayout()
590
+
398
-
399
-
400
-
401
-
402
-
403
- self.present(alert, animated: true, completion: nil)
404
-
405
- print("edit")
406
-
407
- }
591
+ }
408
-
409
- edit.backgroundColor = .orange
592
+
410
-
411
-
412
-
413
- return [delete,edit]
593
+
414
-
415
- }
416
-
417
-
418
-
419
- //Method Swipe from left
420
-
421
- //左から右へスワイプ
422
-
423
- func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) ->UISwipeActionsConfiguration? {
424
-
425
-
426
-
427
- let delete = UITableViewRowAction(style: .normal, title: "削除") {ation, index in
428
-
429
- self.kei.remove(at: (indexPath.row))
430
-
431
- tableView.deleteRows(at: [indexPath], with: .fade)
432
-
433
- }
434
-
435
- return [delete]
436
-
437
- }
438
-
439
-
440
-
441
- func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
442
-
443
-
444
-
445
- if kei.count > (indexPath.row + 1) {
446
-
447
- return true
448
-
449
- }else{
450
-
451
- return false
452
-
453
- }
454
-
455
- }
456
-
457
-
458
-
459
- override func didReceiveMemoryWarning() {
460
-
461
- super.didReceiveMemoryWarning()
462
-
463
- // Dispose of any resources that can be recreated.
464
-
465
- }
466
-
467
-
468
594
 
469
595
  }
470
596
 
597
+
598
+
471
599
  ```
472
-
473
-
474
-
475
- 右からのスワイプに関しては色々ネットにやり方が載っているのですが左から右にスワイプする方法に関しるやり方があまり載っていなくappleの公式ドキュメントやQiitaを参考に私なりにコードを書いてみたのですがエラーが出ておりどうすればできるのかを知りたいです。
476
-
477
-
478
-
479
- **やりたいこと**
480
-
481
- 各cellの先頭だけを左から右にスワイプして削除できるようにしたいです。
482
-
483
-
484
-
485
- **出来たこと**
486
-
487
- 左から右に関するスワイプのコード
488
-
489
- ```
490
-
491
- //左から右へスワイプ
492
-
493
- func tableView(_ tableView: UITableView,
494
-
495
- leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
496
-
497
-
498
-
499
- let delete = UIContextualAction(style: .normal,title: "削除",handler: { (action: UIContextualAction, view: UIView, success :(Bool) -> Void) in
500
-
501
- self.kei.remove(at: (indexPath.row))
502
-
503
- tableView.deleteRows(at: [indexPath], with: .fade)
504
-
505
- })
506
-
507
-
508
-
509
- return UISwipeActionsConfiguration(actions: [delete])
510
-
511
- }
512
-
513
-
514
-
515
- ```
516
-
517
- ![イメージ説明](799b1aa83cb88d590fe28f1279181229.png)
518
-
519
-
520
-
521
- まずios11にしてからコードを上記のようにしたら左から右にスワイプして削除できるようになりました。
522
-
523
- しかし、スワイプして削除してもスワイプした状態が続いていてそれを戻すには自分でまた元に戻さないといけないのでスワイプして削除が完了したらそのままスワイプの状態がなくなるようにしたいです。

2

スワイプに関する処理

2017/10/24 05:06

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -482,31 +482,31 @@
482
482
 
483
483
 
484
484
 
485
+ **出来たこと**
486
+
485
487
  左から右に関するスワイプのコード
486
488
 
487
489
  ```
488
490
 
489
- //Method Swipe from left
490
-
491
- //左から右へスワイプ
491
+ //左から右へスワイプ
492
+
492
-
493
+ func tableView(_ tableView: UITableView,
494
+
493
- func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) ->UISwipeActionsConfiguration? {
495
+ leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
494
-
495
-
496
-
496
+
497
+
498
+
497
- let delete = UITableViewRowAction(style: .normal, title: "削除") {ation, index in
499
+ let delete = UIContextualAction(style: .normal,title: "削除",handler: { (action: UIContextualAction, view: UIView, success :(Bool) -> Void) in
498
-
500
+
499
- self.kei.remove(at: (indexPath.row))
501
+ self.kei.remove(at: (indexPath.row))
500
-
502
+
501
- tableView.deleteRows(at: [indexPath], with: .fade)
503
+ tableView.deleteRows(at: [indexPath], with: .fade)
502
-
504
+
503
- }
505
+ })
504
-
506
+
507
+
508
+
505
- return [delete]
509
+ return UISwipeActionsConfiguration(actions: [delete])
506
-
507
- }
508
-
509
-
510
510
 
511
511
  }
512
512
 
@@ -514,6 +514,10 @@
514
514
 
515
515
  ```
516
516
 
517
- **エラー内容**
518
-
519
- ![イメージ説明](010892237d423ec1a6e9f191f65f0d85.png)
517
+ ![イメージ説明](799b1aa83cb88d590fe28f1279181229.png)
518
+
519
+
520
+
521
+ まずios11にしてからコードを上記のようにしたら左から右にスワイプして削除できるようになりました。
522
+
523
+ しかし、スワイプして削除してもスワイプした状態が続いていてそれを戻すには自分でまた元に戻さないといけないのでスワイプして削除が完了したらそのままスワイプの状態がなくなるようにしたいです。

1

コードの変更

2017/10/22 05:18

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -420,25 +420,21 @@
420
420
 
421
421
  //左から右へスワイプ
422
422
 
423
- func tableView(_ tableView: UITableView,leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
423
+ func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) ->UISwipeActionsConfiguration? {
424
-
425
-
426
-
424
+
425
+
426
+
427
- let removeAction = UIContextualAction(style: .normal,title: "削除",handler: { (action: UIContextualAction, view: UIView, success :(Bool) -> Void)in success(true)
427
+ let delete = UITableViewRowAction(style: .normal, title: "削除") {ation, index in
428
-
429
- })
428
+
430
-
431
- removeAction.image = UIImage(named: "trash")
432
-
433
- removeAction.backgroundColor = .red
429
+ self.kei.remove(at: (indexPath.row))
434
-
435
-
436
-
430
+
437
- return UISwipeActionsConfiguration(actions: [removeAction])
431
+ tableView.deleteRows(at: [indexPath], with: .fade)
438
-
432
+
439
- }
433
+ }
434
+
440
-
435
+ return [delete]
436
+
441
-
437
+ }
442
438
 
443
439
 
444
440
 
@@ -494,21 +490,23 @@
494
490
 
495
491
  //左から右へスワイプ
496
492
 
497
- func tableView(_ tableView: UITableView,leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
493
+ func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) ->UISwipeActionsConfiguration? {
498
-
499
-
500
-
494
+
495
+
496
+
501
- let removeAction = UIContextualAction(style: .normal,title: "削除",handler: { (action: UIContextualAction, view: UIView, success :(Bool) -> Void)in success(true)
497
+ let delete = UITableViewRowAction(style: .normal, title: "削除") {ation, index in
498
+
502
-
499
+ self.kei.remove(at: (indexPath.row))
500
+
501
+ tableView.deleteRows(at: [indexPath], with: .fade)
502
+
503
- })
503
+ }
504
-
505
- removeAction.image = UIImage(named: "trash")
504
+
506
-
507
- removeAction.backgroundColor = .red
505
+ return [delete]
508
-
509
-
510
-
506
+
511
- return UISwipeActionsConfiguration(actions: [removeAction])
507
+ }
508
+
509
+
512
510
 
513
511
  }
514
512