2016-02-17 121 views
0

我知道Objective-C存在同樣的問題,它沒有答案,但也許有人有一個想法。Swift:UITableView單元格中的按鈕被滑動刪除觸發

我有一個的UIButton的UITableView細胞:

let tButton = UIButton(type: UIButtonType.Custom) 
tButton.addTarget(self, action: "buttonTap:", forControlEvents: .TouchUpInside) 
cell.contentView.addSubview(tButton) 

而且我commitEditingStyle委託看起來是這樣的:

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

    if (editingStyle == UITableViewCellEditingStyle.Delete) { 

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

當我在按鈕啓動刷卡,按鈕目標被解僱。

swipe2delTriggers

回答

0

好了,結束了:

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 

    } 
} 

不是很優雅,但它的工作原理。晚安

相關問題