IOS 8 UItableView滑动以删除

IOS 8 UItableView滑动以删除,uitableview,ios8,delete-row,swipe-gesture,Uitableview,Ios8,Delete Row,Swipe Gesture,我有一个UIviewController,它包含一个UITableView,这是一个非常简单的代码,我只想滑动一个单元格,显示更多,删除和处理这两个事件,这是我非常简单的类 class ViewController: UIViewController , UITableViewDataSource , UITableViewDelegate { @IBOutlet weak var tableView: UITableView! let deleteClosure = { (action:

我有一个UIviewController,它包含一个UITableView,这是一个非常简单的代码,我只想滑动一个单元格,显示更多,删除和处理这两个事件,这是我非常简单的类

class ViewController: UIViewController  , UITableViewDataSource , UITableViewDelegate {

@IBOutlet weak var tableView: UITableView!

let deleteClosure = { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
    println("Delete closure called")
}

let moreClosure = { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
    println("More closure called")
}



override func viewDidLoad()
{
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let identifier = "Cell"
    let cell = tableView.dequeueReusableCellWithIdentifier(identifier, forIndexPath: indexPath) as UITableViewCell

    cell.textLabel?.text = "\(indexPath.row)"

    return cell
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 100
}


func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]?
{
    var moreAction = UITableViewRowAction(style: .Default , title: "More") { (action : UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in

        println("more")
    }
    moreAction.backgroundColor = UIColor.lightGrayColor()

    var deleteAction = UITableViewRowAction(style: .Default, title: "Delete") { (action: UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in

        println("delete")
    }

    return [moreAction , deleteAction]
}

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
{
    if (editingStyle == .Delete)
    {
        println("delete1")

    }
    if(editingStyle == .Insert)
    {
        println("insert")

    }

}
调用了EditActionsErrorWatIndeXPath函数,但没有显示任何RowActions!
有什么问题吗

您需要在自定义按钮的处理程序中执行一些操作

例如,使用自定义的“删除”按钮(只需更改其标签和背景颜色),您可以执行以下操作:

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
    let button = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: NSLocalizedString("TitleOfDeleteButton", comment: "Delete"), handler: { (rowAction, indexPath) -> Void in
        self.tableView(self.tableView!, commitEditingStyle: UITableViewCellEditingStyle.Delete, forRowAtIndexPath: indexPath)
    })
    button.backgroundColor = UIColor.lightGrayColor()
    return [button]
}
另外,不要忘记,UITableViewDelegate协议的这种方法仅在iOS8中提供