简体   繁体   English

滑动即可删除UITableViewCell

[英]Swipe to delete UITableViewCell

I'm trying to create a "swipe to delete" in the UITableViewCell . 我正在尝试在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 但是我在创建delete rowAction的行中遇到以下错误

Could not find member 'Normal' 找不到会员'正常'

What am I doing wrong, and how can I fix it? 我做错了什么,我该如何解决?

Update 1 更新1

I tried UITableViewRowActionStyle.Normal as @rmaddy pointed out. 我试图UITableViewRowActionStyle.Normal作为@rmaddy指出。

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. 我在delete var之后得到了这个,并没有给我一个错误。 It works fine: 它工作正常:

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

Update 2 更新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. 当我删除该行时,错误就消失了。

change this 改变这一点

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

TO because that method is expecting an array of indexPath TO 因为该方法需要一个indexPath数组

self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM