2017-02-28 27 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 
    } 
} 

此代碼沒有禁用在單元格中滑動。但是,當滑動單元刪除選項出現。請任何人都可以幫助解決這個問題。如果條件在swift中爲false,禁用swipe中的單元格?

+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方法中不需要檢查條件。

相關問題