Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
- let delete = UIContextualAction(style: .normal, title: "") { (action, view, completion) in
- self.onDeleteCell(indexPath)
- completion(true)
- }
- delete.backgroundColor = UIColor.red
- delete.image = #imageLiteral(resourceName: "x_circle")
- let config = UISwipeActionsConfiguration(actions: [delete])
- config.performsFirstActionWithFullSwipe = false
- return config
- }
- func onDelete(_ indexPath: IndexPath) {
- AlertController.showActionSheet(self, title: nil, message: nil, actionOneTitle: "Delete", actionOneStyle: .destructive, actionTwoTitle: "Dismiss", actionTwoStyle: .cancel) { (_) in
- self.updateCells(indexPath)
- }
- }
- //From custom AlertController class
- static func showActionSheet(_ inViewController: UIViewController, title: String?, message: String?, actionOneTitle: String, actionOneStyle: UIAlertAction.Style, actionTwoTitle: String, actionTwoStyle: UIAlertAction.Style, actionOneHandler: @escaping ((UIAlertAction) -> Void)) {
- let alert = UIAlertController(title: title, message: message, preferredStyle: .actionSheet)
- let actionOne = UIAlertAction(title: actionOneTitle, style: actionOneStyle, handler: actionOneHandler)
- alert.addAction(actionOne)
- let actionTwo = UIAlertAction(title: actionTwoTitle, style: actionTwoStyle, handler: nil)
- alert.addAction(actionTwo)
- inViewController.present(alert, animated: true, completion: nil)
- }
Add Comment
Please, Sign In to add comment