2013-07-23 2 views
0

UITableView에는 2 개의 다른 고유 식별자가있는 UITableViewCell이 있습니다.셀 재로드에서 이전 행의 UITableViewCell 내용이 계속 표시됩니다.

첫 번째 사용자 정의 UITableViewCellLoad에로드 한 다음 두 번째 사용자 정의 UITableViewCellCell Select에로드합니다.

내 문제는 내 셀을 재사용하는 방식과 관련이 있다는 것을 알고 있습니다. 그러나 사용하려고 시도했습니다

routineSearchSelectedResultCell * cell = (routineSearchSelectedResultCell*)[tableView dequeueReusableCellWithIdentifier:nil]; 결과는 새로운 UITableViewCell이 비어 있으며 속성이 채워지지 않습니다.

나는 또한 [[[cell contentView] subviews] makeObjectsPerformSelector: @selector(removeFromSuperview)];을 시도했지만 동일한 결과를 제공합니다.

어떻게이 문제를 해결할 수 있습니까 ??

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if (idp && idp.row == indexPath.row ) { 
     return [self tableViewRoutineSelectedResult:tableView cellForRowAtIndexPath:indexPath]; 
    } 

    NSString *cellIdentifier = @"routineSearchCell"; 
    routineSearchCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (!cell) { 
     cell = [[routineSearchCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; 
    } 


    cell.routineName.text = _myDownloadedInfo[@"routines"][indexPath.row][@"routine"][@"routineName"]; 
    cell.routineAuthor.text = _myDownloadedInfo[@"routines"][indexPath.row][@"routine"][@"username"]; 

    return cell; 

} 
- (routineSearchSelectedResultCell *)tableViewRoutineSelectedResult:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSDictionary* myRoutine = _myDownloadedInfo[@"routines"][indexPath.row][@"routine"]; 

    [self sortOutRoutineImages:myRoutine[@"routineType"]]; 

    NSString *cellIdentifier = @"routineSearchSelectedResultCell"; 
    routineSearchSelectedResultCell * cell = (routineSearchSelectedResultCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    if (!cell) { 
     cell = [[routineSearchSelectedResultCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; 
    } 

    cell.label1.text [email protected]"test"; 
    cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"BlackGradientSearch"]]; 
    cell = [self iconRoutineImagesController:cell]; 
    cell.imgInstruction.image = [UIImage imageNamed:@"InstructionSearchWhite"]; 
    cell.imgVideos.image = [UIImage imageNamed:@"VideoSearchWhite"]; 
    cell.routineName.text = myRoutine[@"routineName"]; 
    [cell.download setBackgroundImage:[UIImage imageNamed:@"DownloadSearchWhite"] forState:UIControlStateNormal]; 
    return cell; 
} 
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if (idp) { 
     NSIndexPath* pIdp = [[NSIndexPath alloc] init]; 
     pIdp = idp; 
     idp = indexPath; 
     [tableView beginUpdates]; 
     [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft]; 
     [tableView reloadRowsAtIndexPaths:@[pIdp] withRowAnimation:UITableViewRowAnimationRight]; 
     [tableView endUpdates]; 
    } else { 
     idp = [[NSIndexPath alloc]init]; 
     idp = indexPath; 
     [tableView beginUpdates]; 
     [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft]; 
     [tableView endUpdates]; 
    } 



} 

+0

은 그래서 당신은'IDP를 할당 가정 메신저 .. 당신을 도움이 될 수 있습니다. 행'을 선택하고'reloadData'를 호출하면됩니까? – KDaker

+0

방금'didSelectRowAtIndexPath' 코드를 추가했습니다 –

+0

그래서 문제가 정확히 무엇입니까? 그림에서 셀이로드중인 것 같습니다. 다시로드하면 사라질 것으로 예상됩니까? – KDaker

답변

0

을 시도해보십시오있는 UITableViewCell 객체 재사용 - 즉 경우

-(void)prepareForReuse 

을 무시하는, 그것은 재사용 식별자 -이 방법은 객체가에서 반환되기 직전에 호출이 UITableView 메서드 dequeueReusableCellWithIdentifier :. 성능상의 이유로, 내용과 관련이없는 셀의 속성 (예 : 알파, 편집 및 선택 상태) 만 재설정해야합니다. tableView의 delegate : cellForRowAtIndexPath :는 셀을 재사용 할 때 항상 모든 내용을 재설정해야합니다. 셀 객체에 관련 재사용 식별자가없는 경우이 메서드는 호출되지 않습니다. 이 메서드를 재정의하는 경우 수퍼 클래스 구현을 호출해야합니다.

이를 사용하는 .. 시도를 내가 생각하는 document

0

당신이 레이블을 사용하고 그들이 중복되는 참조, 그것은

for(UIView *view in cell.subviews){ 
    if([view isKindOfClass:[UILabel class]]){ 
    [view removeFromSuperview]; 
    } 
} 
관련 문제