2017-12-23 14 views
0

동일한 UIViewController에서 2 개의 UITableView (Table-1 & Table-2)가 있습니다. 내 Table-2에서 기능을 편집하고 싶습니다. 아래에 언급 한 바와 같이UITableView에서 삭제하기 위해 스 와이프 옵션을 비활성화하는 방법

내보기 컨트롤러에있는 tableview 데이터 소스 방법을 추가했습니다 : -

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 
     if editingStyle == .delete { 

      tableView.beginUpdates() 
      myArray.remove(at: indexPath.row) 
      tableView.deleteRows(at: [indexPath], with: .fade) 
      tableView.endUpdates() 
     } 
    } 

모두의 tableview이 메소드를 호출. 그래서 각 테이블 뷰 셀은 삭제 옵션을 열 수 있습니다.

하지만이 삭제 옵션은 Table-2에서만 필요합니다. Table-1에서 삭제 편집 옵션 기능을 제한하고 싶습니다.

도와주세요. 미리 감사드립니다.

답변

1

당신은 UITableViewDelegate에서 제공하는이 기능을 사용할 수 있습니다 : 당신이에서 편집을 허용 할 경우

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 
    return true 
} 

간단히 확인하려면 몇 가지 논리를 구현하는 indexPath를 제공하고 원하는 경우 tableViewreturn true을 부여 편집/삭제 및 return false 경우 너는하지 않는다.

희망이 도움이됩니다.