2013-08-24 1 views
2

사용자가 셀을 탭하면 내 UITableView을 업데이트하려고합니다. 이 탭 셀의 내용을 포함하여 가장 쉬운 방법은 내부 매개 변수를 업데이트 한 다음 [self.tableView reloadData];을 호출하는 것입니다. 셀 선택 애니메이션을 중지하지 않고 UITableView를 다시로드하는 방법

그러나, reloadData 즉시 내 탭 셀의 좋은 블루 -> 없음 선택 애니메이션을 중지합니다.

탭 셀의 애니메이션을 중단하지 않고 표 셀을 업데이트하는 방법이 있습니까?

참고 :이 경우에는 셀을 추가하거나 삭제하지 않습니다. 난 그냥 변경 (예를 들어, 작업 표시기를 시작하거나 라벨의 색상을 변경할 수 있습니다.)

답변

1

를 귀하의 경우에는 방금 보이는 모든 세포에 대한 포인터를 얻을하고 업데이트 할 수 있습니다하는 내용으로합니다. 이런 식으로 뭔가 :

- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
    NSArray* visibleCells = [tableView indexPathsForVisibleRows]; 

    for (NSIndexPath* indexPath in visibleCells) 
    { 
     UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath]; 

     [self updateCell:cell atIndexPath:indexPath]; // Your method, which updates content... 
    } 
} 

그리고 콘텐츠 다른 세포를 업데이트 할 경우이 같은 것을 사용할 수 있습니다

- (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
    [self updateCell:cell atIndexPath:indexPath]; // Your method, which updates content... 
} 

그래서 당신의 세포가 항상 정확한 내용을 표시합니다.

만드는 내용 정보

:

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString* CellIdentifier = @"Cell"; 
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 

     [self createContentForCell:cell atIndexPath:indexPath]; // so here to create content or customize cell 
    } 

    return cell; 
} 
+0

좋아요, 감사 남자! 그러나 이것은 셀 내용 작성 코드를'cellForRowAtIndexPath'에서 멀리 옮기는 것을 의미합니다. 그러나 이것은 어쨌든 좋은 일입니다. –

+1

도움이된다면 기꺼이 도와 드리겠습니다. –

+0

일반적으로 성능 셀의 내용은 cellForRowAtIndexPath 메소드에서 작성됩니다 if (cell == nil) {... // 여기; }. 그리고 willDisplayCell 메서드는 무언가를 업데이트 할 수 있습니다 (예 : 일부 활동 표시기 중지). –

관련 문제