Reputation: 15
I am using the method
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]?
{
let delete = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete" , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
//Do something
})
delete.backgroundColor = UIColor.redColor()
let more = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "More" , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
//Do something
})
more.backgroundColor = UIColor.blueColor()
return [delete, more]
}
I also included
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
// you need to implement this method too or you can't swipe to display the actions
}
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// the cells you would like the actions to appear needs to be editable
return true
}
and when I swipe right or left the buttons I created are not showing up. I tried putting override on the editactionforrowatindexpath but then i get an error saying method does not override any method from its super class
Upvotes: 0
Views: 293
Reputation: 56
There is nothing wrong in your implementation. The function is not getting called is because the delegate and datasource methods are not called properly.
You can connect the delegate and datasource methods by programatically or via storyboard.
When you are implement the tableview programatically You need to add UITableViewDataSource, UITableViewDelegate in class declaration and connect the delegates using this code.
yourTableView.datasource = self
yourTableView.delegate = self
If you are implement tableview through storyboard you just need to connect the delegate and data source method by dragging
Upvotes: 1