2016-08-30 3 views
0

내 사용자 지정 TableViewCell 중 하나의 단추를 누르면 다른 사용자 지정 TableViewCell에서 이미지를 숨기거나 숨김을 취소하고 싶습니다. 내 세포는 섹션으로 정렬됩니다.보기 중에 UITableView 다시로드 섹션

버튼을 누르고 다른보기로 전환 한 다음 다시 내 TableView로 돌아 가면 변경 사항이 적용됩니다. 보기를 전환 할 필요없이 즉시 변경 사항을 표시하고 싶습니다.

내 코드 :

 let otherCellIndexPath = IndexPath(item: 0, section: 0) 
     let otherCell = tableView.cellForRow(at: oldIndexPath) as! CustomTableViewCell 
     otherCell.hideImage() 

     let currentCell = tableView.cellForRow(at: indexPath) as! CustomTableViewCell 
     currentCell.showImage() 

     tableView.beginUpdates() 
     tableView.reloadSections([otherCellIndexPath,indexPath], with: .none) 
     tableView.endUpdates() 

나는 무엇을 놓치고? (Xcode 8 b6, Swift 3 사용)

+0

'tableview.reloadData()'를 시도 했습니까? – John

+1

테이블 뷰를 숨기고 다시로드하려는 배열에서 객체를 제거하기 만하면됩니다. –

답변

1

내 코드에서 cellForRow를 호출하지 마십시오. 대신 각 셀의 상태에 대한 사전을 유지합니다.

var dictSection0 = [["ImageName" : "SampleImageSection0Row0","hidden":true],["ImageName" : "SampleImageSection0Row1","hidden":false]] 

var dictSection1 = [["ImageName" : "SampleImageSection1Row0","hidden":true],["ImageName" : "SampleImageSection1Row1","hidden":false]] 
var tableDataModel = [dictSection0,dictSection1] 

버튼을 누르면 사전이 수정됩니다. 위의 경우 섹션 0

var rowDict = tableDataModel[0][1] 
rowDict["hidden"] = true 

의 1 행에 대해 true로 숨겨 후 변경 사항을 반영하기 위해 전체 테이블 (또는 당신이하고있는 것처럼 그것의 일부를) 다시 설정을.

cellForRow atIndexPath 메서드에서이 사전은 셀의 이미지를 표시하거나 숨기는 데 사용됩니다.

var rowData = tableDataModel[indexPath.section][indexPath.row] 
let tableCell = tableView.dequeueReusableCellWithIdentifier("customCell", forIndexPath: indexPath) 
tableCell.imageView.hidden = rowDict["hidden"] 
1

이 @Manali이해야 할 제안 무엇, tableView.reloadSections를 호출하면 cellForRowAtIndexPath에 대한 일련의 호출을 트리거, 메소드 내부의 대기열 세포는 cellForRow를 호출하여 얻을 하나의 오른쪽과 동일한 대상이되지 않을 수도 있습니다 방법은 숨기기/숨기기에 대한 정보를 저장하고 내부에 이미지를 표시/숨기기입니다. cellForRowAtIndexPath