无法在UITableView编辑模式下删除按钮

无法在UITableView编辑模式下删除按钮,uitableview,swift,Uitableview,Swift,当我的UITableView处于编辑模式并按下删除按钮(-)时,我会在行中隐藏编辑按钮,并显示删除和取消按钮 如果按下Cancel按钮,我就没事了,因为它会触发按钮的Cancel处理程序,我会重新显示Edit按钮 但是,如果用户在该行内按(而不是“取消”或“删除”按钮),该行将退出删除模式,而不允许我显示编辑按钮 当删除模式退出或在删除模式下按下行时,是否存在我可以检测到的事件 func tableView(tableView: UITableView!, editActionsForRowAt

当我的UITableView处于编辑模式并按下删除按钮(-)时,我会在行中隐藏编辑按钮,并显示删除和取消按钮

如果按下Cancel按钮,我就没事了,因为它会触发按钮的Cancel处理程序,我会重新显示Edit按钮

但是,如果用户在该行内按(而不是“取消”或“删除”按钮),该行将退出删除模式,而不允许我显示编辑按钮

当删除模式退出或在删除模式下按下行时,是否存在我可以检测到的事件

func tableView(tableView: UITableView!, editActionsForRowAtIndexPath indexPath: NSIndexPath!) -> [AnyObject]!
{
// hide the Edit button in this row
self.editButtons[indexPath.row].hidden = true

// create a Cancel button to abort delete
var cancelAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Cancel", handler:  
{( 
    action: UITableViewRowAction!, indexPath: NSIndexPath!) in

// if Cancel pressed, show the Edit button again 
self.editButtons[indexPath.row].hidden = false

// reload the row to get rid of the Delete and Cancel buttons   
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)

return
})

var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete",handler:
{( 
action: UITableViewRowAction!, indexPath: NSIndexPath!) in
    println("Delete not implemented")
    return
})
return [deleteAction, cancelAction]
}

您可以覆盖
UITableViewCell
中的
willTransitionOnState
函数,以跟踪状态更改。 您必须跟踪
以前的状态
,以检查删除按钮是否被隐藏

class CustomCell : UITableViewCell
{
    var previousState : UITableViewCellStateMask = UITableViewCellStateMask.allZeros

    override func willTransitionToState(state: UITableViewCellStateMask) {
        if state & UITableViewCellStateMask.ShowingEditControlMask != nil
        {
            if previousState & UITableViewCellStateMask.ShowingDeleteConfirmationMask != nil
            {
                println("hiding delete")
                /* Send a notification or call a function by setting a 
                   delegate from the view controller.*/
            }

        }
        previousState = state
    }
}

这看起来是正确的答案。当我退出编辑模式时,它正在点击该函数。但是,我是Swift新手,需要弄清楚如何在视图控制器中设置和调用代理。