2011-04-07 2 views
1

UITableView에서 마지막 셀에 로딩 표시기를 표시하려고합니다. 나머지 셀의 경우 제대로 작동하는 사용자 정의 테이블보기 셀을 만들었습니다. 하지만 끝으로 스크롤하면 크래시가 발생하고로드 인디 터 (다른 사용자 정의 셀 뷰)를로드 할 수 없습니다. 여기 내 코드가있다.iPhone - 두 가지 다른 사용자 정의 셀보기를 표시하는 UITableView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{  
    static NSString *CellIdentifier = @"HomeViewCell"; 

    UITableViewCell* cellToReturn = nil; 

    // Configure the cell. 
    NSInteger row = [indexPath row]; 
    if (row < [jokesTableArray count]) 
    { 
     CustomTableCell* cell = (CustomTableCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) 
     { 
      cell = [[[CustomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     } 
     NSDictionary* dict = [jokesTableArray objectAtIndex:indexPath.row]; 
     NSNumber* rating = [[ServerCommunicator getInstance] getCurrentUserJokeRating:[dict objectForKey:@"id"]]; 
     cell.userRatedTheJoke = rating != nil ? YES : NO; 
     cell.titleLabel.text = [dict objectForKey:@"title"]; 
     cell.descriptionLabel.text = [dict objectForKey:@"text"]; 
     cell.upVotes.text = [NSString stringWithFormat:@"%2.2f",[[dict objectForKey:@"rating_count"] floatValue]]; 
     [cell setRating:rating != nil ? [rating intValue] : [[dict objectForKey:@"rating_count"] intValue]]; 
     NSString* authorName = [dict objectForKey:@"author"]; 
     if (authorName != nil && ![authorName isEqual:[NSNull null]]) 
     { 
      cell.author.text = [NSString stringWithFormat:@"By:%@",authorName];  
     } 
     cellToReturn = cell; 
    } 
    else 
    { 
     KMLoadingIndicatorCell* cell = (KMLoadingIndicatorCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) 
     { 
      KMLoadingIndicatorCell* cell = [[[KMLoadingIndicatorCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
      cell.loadingLabel.text = @"Loading..."; 
      cellToReturn = cell; 
     } 
    } 

    return cellToReturn; 
} 

답변

0

사용자 지정 셀에 다른 셀 식별자를 사용해야합니다.

1

같은 reuseIdentifier을 사용하고 있기 때문에, 라인

KMLoadingIndicatorCell* cell = (KMLoadingIndicatorCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

가장 가능성이 오히려 예상 KMLoadingIndicatorCell보다, 지금은 재사용되고 CustomTableCell의 인스턴스에 cell 설정입니다. 두 가지 유형의 셀에 대해 서로 다른 식별자를 사용해야합니다.

관련 문제