Guest User

Untitled

a guest
Nov 14th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
  2. let delete = UIContextualAction(style: .normal, title: "") { (action, view, completion) in
  3. self.onDeleteCell(indexPath)
  4. completion(true)
  5. }
  6.  
  7. delete.backgroundColor = UIColor.red
  8. delete.image = #imageLiteral(resourceName: "x_circle")
  9.  
  10. let config = UISwipeActionsConfiguration(actions: [delete])
  11.  
  12. config.performsFirstActionWithFullSwipe = false
  13.  
  14. return config
  15. }
  16.  
  17. func onDelete(_ indexPath: IndexPath) {
  18. AlertController.showActionSheet(self, title: nil, message: nil, actionOneTitle: "Delete", actionOneStyle: .destructive, actionTwoTitle: "Dismiss", actionTwoStyle: .cancel) { (_) in
  19. self.updateCells(indexPath)
  20. }
  21. }
  22.  
  23.  
  24. //From custom AlertController class
  25. static func showActionSheet(_ inViewController: UIViewController, title: String?, message: String?, actionOneTitle: String, actionOneStyle: UIAlertAction.Style, actionTwoTitle: String, actionTwoStyle: UIAlertAction.Style, actionOneHandler: @escaping ((UIAlertAction) -> Void)) {
  26.  
  27. let alert = UIAlertController(title: title, message: message, preferredStyle: .actionSheet)
  28. let actionOne = UIAlertAction(title: actionOneTitle, style: actionOneStyle, handler: actionOneHandler)
  29. alert.addAction(actionOne)
  30.  
  31. let actionTwo = UIAlertAction(title: actionTwoTitle, style: actionTwoStyle, handler: nil)
  32. alert.addAction(actionTwo)
  33.  
  34. inViewController.present(alert, animated: true, completion: nil)
  35. }
Add Comment
Please, Sign In to add comment