Skip to content

Instantly share code, notes, and snippets.

@JoshBroomberg
Created June 13, 2016 11:26
Show Gist options
  • Save JoshBroomberg/e0fbb6214eb19db3eafb0047fda67e7b to your computer and use it in GitHub Desktop.
Save JoshBroomberg/e0fbb6214eb19db3eafb0047fda67e7b to your computer and use it in GitHub Desktop.
Code for adding custom TableRowActions to swift tables.
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return //return something that makes sense here.
}
// This is a generic implementation of the table data source method for adding row actions.
// Adapt it to match your needs.
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let action1 = UITableViewRowAction(style: .Normal, title: "Action 1") { action, index in
print("Action 1 tapped")
}
action1.backgroundColor = UIColor.blueColor()
let action2 = UITableViewRowAction(style: .Normal, title: "Action 2") { action, index in
print("Action 2 tapped")
}
action2.backgroundColor = UIColor.greenColor()
return [action1, action2]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment