2012-11-01 2 views
0

2 개의 다른 섹션에서 2 개의 행의 데이터를 변경하려고합니다. 그 중 하나가 선택되면 동일한 섹션이 만들어져 동일한 대답을 갖게됩니다. 하지만 작동하지 않습니다 :다른 섹션에서 uitableviewcell 데이터를 변경하는 방법?

NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:row1 inSection:section1]; 
    cell = [self.tableView cellForRowAtIndexPath:indexPath1]; 
    //DO SOMETHING WITH CELL LABEL 


    NSIndexPath *indexPath2 = [NSIndexPath indexPathForRow:row2 inSection:section2]; 
    cell = [self.tableView cellForRowAtIndexPath:indexPath2]; 
    //MAKE THIS CELL LABEL SAME AS THE LAST ONE 

두 번째 셀이 다른 섹션에 있으면 작동하지 않습니다! 어떠한 제안?

+0

없습니다. 데이터를 변경하고 셀, 섹션 또는 전체 테이블을 다시로드해야합니다. –

답변

1

당신은 cellForRowAtIndexPath에서 전무를 얻을 것이다 : 세포 중 하나가 순간에 보이지 않는합니다. 따라서 UI에서가 아니라 데이터 모델에서 필요한 항목을 가져와야합니다. 이 필요한 정보를 변경 :

NSArray *section1Data = [self.dataModell objectAtIndex:section1]; 
NSDictionary *dataObject1 = [section1Data objectAtIndex:row1]; 
[dataObject1 setValue:@"My new Text." forKey:@"theTextPropertyKey"]; 

NSArray *section2Data = [self.dataModell objectAtIndex:section2]; 
NSDictionary *dataObject2 = [section1Data objectAtIndex:row2]; 
[dataObject2 setValue:@"My new Text." forKey:@"theTextPropertyKey"]; 

그런 다음 UI에 필요한 세포를 다시로드 :이 그것을 할 수있는 방법은

NSArray *indexPaths = @[indexPath1, indexPath2]; 
[self.tableView reloadRowsAtIndexPaths:indexPaths]; 
관련 문제