Created
April 23, 2017 18:08
-
-
Save YonathanMeguira/a38652d5ae5a9dbe80cf9d0237e5720e to your computer and use it in GitHub Desktop.
tableview editing action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { | |
let delete = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexPath) in | |
// delete item at indexPath | |
self.todo.remove(at: indexPath.row) | |
tableView.deleteRows(at: [indexPath], with: .fade) | |
} | |
let share = UITableViewRowAction(style: .default, title: "Share") { (action, indexPath) in | |
// share item at indexPath | |
let shareOption = UIAlertController(title: nil, message: "choose sharing option", preferredStyle: .actionSheet) | |
let shareOnFacebook = UIAlertAction(title: "Facebook", style: .default, handler: { | |
(alert: UIAlertAction!) -> Void in | |
print("File Deleted") | |
}) | |
let shareOnTwitter = UIAlertAction(title: "Twitter", style: .default, handler: { | |
(alert: UIAlertAction!) -> Void in | |
print("File Saved") | |
}) | |
shareOption.addAction(shareOnFacebook) | |
shareOption.addAction(shareOnTwitter) | |
self.present(shareOption, animated: true, completion: nil) | |
} | |
share.backgroundColor = UIColor.lightGray | |
return [delete, share] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment