2012-09-30 2 views
0

tableviewcell을 사용하여 앱을 프로그래밍하고 있습니다. 셀을 만지면 다른 뷰 컨트롤러로 이동하여 스위치를 활성화하고 plist 파일에이 상태를 저장합니다. Back to tableviewcell plist 파일에서 정보를 읽고 터치 및 활성화 된 셀의 배경색을 업데이트합니다. 문제는 셀을 볼 수있는 경우 탐색 버튼이 배경색을 표시하지 않지만 다시 tableview 셀로 돌아갈 때입니다. 아래로 스크롤하면 색상 셀이 업데이트됩니다. reloadData 메서드를 시도했지만 성공하지 못했습니다. IOS API에서 보이는 셀은 reloadData 메소드로 업데이트됩니다. 미리 감사드립니다. 다른보기 컨트롤러에서 전환 할 때 이미로드 셀이 표시 될 때 willDisplayCell으로tableviewcell에서 시각적 셀을 업데이트하지 않습니다.

- (void)viewWillAppear:(BOOL)animated { 
controladorRegistre = [[ControladorRegistres alloc]initRegistreAmbCategoria]; 
[self.tableCategories reloadData]; 
[super viewWillAppear:animated]; 

} 

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell  *)cell 
      forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
//Pinta la celda si esta activada 
registre = [controladorRegistre getRegistreCategoria:cell.textLabel.text]; 
BOOL estaActivat = [[registre objectForKey:@"estaActivat"] boolValue]; 
if (estaActivat) { 
    [cell setBackgroundColor:[UIColor redColor]]; 
}else{ 
    cell.backgroundColor = [UIColor whiteColor]; 
} 
} 
+0

'willDisplayCell'이 호출되는지 확인 했습니까? – Mundi

+0

그것이라고 부르지 만, 하위 뷰에서 돌아 왔을 때, 아래로 스크롤 할 때까지, 그러면 컬러 셀이 업데이트됩니다. – Sep

답변

0

가 자동으로 호출되지 않습니다, 당신은 viewWillAppear로 업데이트 코드를 삽입해야합니다.

나는 보통 이것을 updateCells과 같은 별도의 방법으로 구분합니다.

일반적으로 [_tableView visibleCells] 또는 indexPathsForVisibleCells으로 관련 셀에 액세스 할 수 있습니다. 귀하의 경우에는 두 번째보기 컨트롤러를 시작한 셀의 참조를 유지하고이를 사용할 수 있습니다.

관련 문제