Created
June 13, 2016 11:26
-
-
Save JoshBroomberg/e0fbb6214eb19db3eafb0047fda67e7b to your computer and use it in GitHub Desktop.
Code for adding custom TableRowActions to swift tables.
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
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