Skip to content

Instantly share code, notes, and snippets.

@YonathanMeguira
Created April 23, 2017 18:08
Show Gist options
  • Save YonathanMeguira/a38652d5ae5a9dbe80cf9d0237e5720e to your computer and use it in GitHub Desktop.
Save YonathanMeguira/a38652d5ae5a9dbe80cf9d0237e5720e to your computer and use it in GitHub Desktop.
tableview editing action
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