Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swipe to delete UITableViewCell

I'm trying to create a "swipe to delete" in the UITableViewCell. I tried the following code:

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
{

}

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]?
{
    var delete = UITableViewRowAction(style: .Normal, title: "Delete", handler: { (action:UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
        self.tableView.deleteRowsAtIndexPaths(indexPath, withRowAnimation: .Automatic) // Error
    })
}

But I get the following error at the line of creating the delete rowAction

Could not find member 'Normal'

What am I doing wrong, and how can I fix it?

Update 1

I tried UITableViewRowActionStyle.Normal as @rmaddy pointed out.

but got the following error:

Cannot find an initializer for type 'UITableViewRowAction' that accepts an argument list of type '(style: UITableViewRowActionStyle, title: String, handler: (UITableViewRowAction!, NSIndexPath!) -> Void)'

I had this after the delete var, and it didn't give me an error. It works fine:

var action = UITableViewRowAction(style: .Normal, title: "action", handler: { (action:UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
        println("Action")
})

Update 2

Just realized the problem. When I insert the following action:

self.tableView.deleteRowsAtIndexPaths(indexPath, withRowAnimation: .Automatic)

I get the error. When I remove that line, the error goes away.

like image 581
Jessica Avatar asked Apr 22 '26 18:04

Jessica


1 Answers

change this

self.tableView.deleteRowsAtIndexPaths(indexPath, withRowAnimation: .Automatic)

TO because that method is expecting an array of indexPath

self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
like image 147
Lamour Avatar answered Apr 26 '26 20:04

Lamour



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!