2016-09-12 59 views
2

UITableViewDelegateUITableViewDataSourceのコントローラで管理しているUITableViewがあります。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

あなたのテーブルビューはスクロールビュー内にありますか? –

+0

@KumarKL時にはそれは動作します...しかし、私は理由を知らない。私が10 swypesを試しても1は動作します – Zac

答えて

0

:私はカスタムセルを持っている。この表では、問題は機能editActionsForRowAtIndexPathのみ時々(私は特定の方法で旗上げたときに多分、私は知らない)呼び出されるということです、私のコードは次のようですそれは、このコードで私の作品、このことから始めてみてください、あなたはおそらく見つける問題は

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