2017-10-31 18 views
0

어떤 버튼을 눌렀는지에 따라 셀을 변경하는 tableview가 있습니다. 첫 번째 테이블보기에서 나는 단추를 눌렀을 때만 셀을 스 와이프 할 수 있기를 원합니다. 그렇지 않은 경우 스 와이프 기능을 사용 중지해야합니다. 버튼을 누르면 tableview가 스 와이프 가능하고 원하는 동작을 보여줍니다. 그러나 버튼을 누르지 않으면 셀은 여전히 ​​"삭제"작업으로 스 와이프 가능합니다. 셀 레이블에 현재 사용자의 이름이 포함되어있는 경우 행을 스 와이프 할 수 없도록하고 싶지 않습니다.특정 셀에서만 허용 된 스 와이프

맨 아래 테이블 뷰에 대한 코드를 추가했습니다. 이 문제를 어떻게 해결할 수 있습니까? 1 테이블

코드 :

override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 
       let cell = tableView.cellForRow(at: indexPath) as! DetailsCell 
       let detailsAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "Details") { (action , indexPath) -> Void in 
         if isCharacterButtonPressed == true { //if button is pressed 
          if cell.label != currentUser.name{ 
           let viewController = self.storyboard?.instantiateViewController(withIdentifier: "SeeDetails") as! DetailsVC 
           viewController.person = cell.person    
     self.navigationController?.pushViewController(viewController, animated: true) 
          } else { 
           return .none 
          } 
          return [detailsAction] //makes cell swipe-able 
         } else { //if button is not pressed 
          return .none //do not make the cell swipe-able 
         } 
       } 

편집 :

나는 canEditRow 기능을 고정했지만,이 빨간색 원을 강타 할 수있는 세포의 측면에 표시 때 그들을 문지르십시오. 이 문제를 어떻게 해결할 수 있습니까? enter image description here

답변

1

것은 당신이 셀 모든 편집 작업을 보여주지하는 행동의 빈 배열을 반환 할 때 때문에 사용자 경험은 실수있을 것입니다, tableView(_: UITableView, editActionsForRowAt: IndexPath)에서 편집 작업을 표시할지 여부를 확인하는 경우 : 나는 그것의 스크린 샷을 첨부 마치 잠시 동안 스 와이프 한 다음 스 와이프에 응답하지 않는 것처럼 보입니다. 대신 셀에 대한 편집 작업을 표시할지 여부를 확인하려면 tableview(_:UITableView,canEditRowAt:IndexPath)을 사용하고 다른 기능을 사용하여 셀을 스 와이프 할 수있을 때 실제로 작업을 표시해야합니다.

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 
    let cell = tableView.cellForRow(at: indexPath) as! DetailsCell 
    if isCharacterButtonPressed == true && cell.label != currentUser.name{ 
     return true 
    } else { 
     return false 
    } 
} 
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 
    let cell = tableView.cellForRow(at: indexPath) as! DetailsCell 
    let detailsAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "Details") { (action , indexPath) -> Void in 
    let viewController = self.storyboard?.instantiateViewController(withIdentifier: "SeeDetails") as! DetailsVC 
    viewController.person = cell.person    
    self.navigationController?.pushViewController(viewController, animated: true) 
    }   
    return [detailsAction]   
} 
0

사용 중 tableView(_: UITableView, editActionsForRowAt: IndexPath) 또는 MGSwipTableCell, 부울 (즉 allowSwipe) 만 편집/대는 부울에 해당하는 경우 수를 만들