Swift:如何使用"编辑"按钮删除并停用滑动以删除?

MJQ*_*347 2 uitableview swift

我在导航栏中添加了一个带有IBAction的编辑按钮:

@IBOutlet weak var editButton: UIBarButtonItem!

@IBAction func doEdit(sender: AnyObject) {

    if (self.tableView.editing) {
        editButton.title = "Edit"
        self.tableView.setEditing(false, animated: true)
    } else {
        editButton.title = "Done"
        self.tableView.setEditing(true, animated: true)
    }
}
Run Code Online (Sandbox Code Playgroud)

为了去除我有的细胞

    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if (editingStyle == UITableViewCellEditingStyle.Delete) {
        arr.removeAtIndex(indexPath.row)
        tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
    }
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,这也会激活滑动以删除.如何在不实现swip删除的情况下删除单元格?

Die*_*che 5

解决方案(来自这个答案),翻译成Swift:

override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
    if (self.tableView.editing) {
            return UITableViewCellEditingStyle.Delete;
    }

    return UITableViewCellEditingStyle.None;
}
Run Code Online (Sandbox Code Playgroud)