Swift:UITableView单元格中的按钮被滑动触发以删除

Swift:UITableView单元格中的按钮被滑动触发以删除,uitableview,ios8,uibutton,swift2,Uitableview,Ios8,Uibutton,Swift2,我知道Objective-C也有同样的问题,但没有答案,但也许有人有想法 我在UITableView单元格中有一个UIButton: let tButton = UIButton(type: UIButtonType.Custom) tButton.addTarget(self, action: "buttonTap:", forControlEvents: .TouchUpInside) cell.contentView.addSubview(tButton) 我的委托风格是这样的: fun

我知道Objective-C也有同样的问题,但没有答案,但也许有人有想法

我在UITableView单元格中有一个UIButton

let tButton = UIButton(type: UIButtonType.Custom)
tButton.addTarget(self, action: "buttonTap:", forControlEvents: .TouchUpInside)
cell.contentView.addSubview(tButton)
我的委托风格是这样的:

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

    if (editingStyle == UITableViewCellEditingStyle.Delete) {

        tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
    }
}
当我开始滑动按钮时,按钮目标会被触发

好的,结果是:

func tableView(tableView: UITableView, willBeginEditingRowAtIndexPath indexPath: NSIndexPath) {

    blocked = true
}

func tableView(tableView: UITableView, didEndEditingRowAtIndexPath indexPath: NSIndexPath) {

    blocked = false
}
然后在我的按钮的目标中确定uiStatus,如下所示:

func buttonTap(sender:UIButton!){

    if blocked == false {

        ...do something

    }
}
不是很优雅,但很管用。晚安