Here\'s the dilemma: I want to create a custom editingAccessoryView
that contains two buttons for my stock UITableViewCell
. I\'d like to achieve
I know this is probably too late to help, but it is much better than the solution you found. iOS gives you a method named tableView: editActionsForRowAtIndexPath indexPath:
. This method basically allows you to add your own UITableViewRowActions, which is much easier (and cleaner) than adding an entire UIView with UIButtons.
Apple says:
Use this method when you want to provide custom actions for one of your table rows. When the user swipes horizontally in a row, the table view moves the row content aside to reveal your actions. Tapping one of the action buttons executes the handler block stored with the action object.
If you do not implement this method, the table view displays the standard accessory buttons when the user swipes the row.
You can look at the Apple Documentation yourself, if you want.
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
let customAction = UITableViewRowAction(style: .Normal, title: "Your Custom Action", handler: { (action: UITableViewRowAction!, indexPath: NSIndexPath!) in
println("Do whatever it is you want to do when they press your custom action button")
})
editAction.backgroundColor = UIColor.greenColor()
let deleteAction = UITableViewRowAction(style: .Normal, title: "Delete", handler: { (action: UITableViewRowAction!, indexPath: NSIndexPath!) in
println("You can even implement a deletion action here")
})
deleteAction.backgroundColor = UIColor.redColor()
return [deleteAction, editAction]
}