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

이 코드는 셀에서 스 와이프를 사용 중지하지 않았습니다. 그러나 셀을 스 와이프하면 삭제 옵션이 나타납니다. 누구나이 문제를 해결할 수 있습니다.신속하게 조건이 false이면 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 메서드에서 검사 할 필요가 없습니다.