2017-02-28 12 views
2
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 

    if condition == true { 
    let pause = UITableViewRowAction(style: .Destructive, title: "pause") { action, index in 
      print("pause button tapped") 
      return [pause] 
     } 
    } else { 

     return .None 
    } 
} 

このコードはセル内でスワイプすることはできませんでした。しかし、セルをスワイプすると、削除オプションが表示されます。誰もがこの問題をスローするのを助けることができます。条件が偽である場合、tableView内のセルをスワイプするのを無効にしますか?

+0

http://stackoverflow.com/questions/34550291/disable-cell-swipe-action –

答えて

3

canEditRowAtを使用し、条件に応じてBool値を返す必要があります。

override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 

    if condition == true { 
     return true 
    } 
    return false 
} 

editActionsForRowAtIndexPathメソッドでは条件をチェックする必要はありません。

関連する問題