2016-09-12 41 views
2

我有一個UITableView,我在一個控制器中管理UITableViewDelegateUITableViewDataSource。在這個表中我有一個自定義單元格,問題是該函數editActionsForRowAtIndexPath被調用只是有時(也許當我在一個特定的方式Swype的,我不知道),我的代碼如下:UITableViewRowAction不工作

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    return true 
} 
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 
    let doneAction: UITableViewRowAction 
    //let highlightAction: UITableViewRowAction 
    if(self.compiti[indexPath.row].completato){ 
     doneAction = UITableViewRowAction(style: .Normal, title: "Da Fare") { (UITableViewRowAction, indexPath: NSIndexPath!) -> Void in 
      let compito = self.compiti[indexPath.row] 
      self.db.contrassegnaCompito(compito) 
      UITableViewRowAction 
     } 
     doneAction.backgroundColor = UIColor.redColor() 
    }else{ 
     doneAction = UITableViewRowAction(style: .Normal, title: "Fatto") { (UITableViewRowAction, indexPath: NSIndexPath!) -> Void in 
      let compito = self.compiti[indexPath.row] 
      self.db.contrassegnaCompito(compito) 
     } 
     doneAction.backgroundColor = UIColor(red: 67/255, green: 160/255, blue: 71/255, alpha: 0.7) 
    } 
    return [doneAction] 
} 
+0

你是什麼意思,**也許當我以特定的方式swype,我不知道?** –

+0

是你的tableView裏面的scrollView? –

+0

@KumarKL,有時它的工作原理......但我不知道爲什麼。如果我嘗試10個swypes 1將會工作 – Zac

回答

0

它爲我這個代碼,嘗試從這個開始,你可能會發現,當出現問題時

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    return true 
} 
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 
    var doneAction :UITableViewRowAction! 

    doneAction = UITableViewRowAction(style: .Default, title: "Da Fare") { (UITableViewRowAction, indexPath: NSIndexPath!) -> Void in 
      UITableViewRowAction 
    } 
    return [doneAction] 
} 
+0

仍然沒有行動,我認爲在我的牢房裏還有別的東西可以「捕捉」行動...... – Zac

2

你需要添加此方法實施方案以及否則你將無法刷卡顯示的動作

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 
    // it can be empty 
} 
+0

它的作品適合我。 (根據我們需要使用的版本) – iApple