2011-11-03 3 views
1

다음 코드는 이미지를 맨 위 섹션/셀에 넣은 다음 다른 이미지를 넣어야합니다. 문제는 코드가 화면을 벗어날 때 셀을 재사용하려고하지만 코드를 바꾸어야한다는 것입니다.이미지와 셀을 교체하지 않고 UITableView를 다시 그립니다.

http://screencast.com/t/OoQWMI5zCKVc

코드는 다음과 같다 : 텍스트를 표시됩니다 UITableViewCell의 새로운 인스턴스를 만들 때

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{  
    static NSString *CellIdentifierText = @"TextCell"; 
    static NSString *CellIdentifierImage = @"ImageCell"; 

    if (indexPath.section == 0) 
    { 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierImage]; 

     if (cell == nil) 
     { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierImage] autorelease]; 
      UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,180)];     
      imageView.tag = 1; 
      imageView.image = [UIImage imageNamed:@"prem.jpg"]; 
      [cell addSubview:imageView]; 
      [imageView release]; 
     } 
     return cell; 
    } 
    else { 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierText]; 
     if (cell == nil) 
     { 

      cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifierImage] autorelease]; 
     }  
     if(indexPath.section == 1)   
      cell.textLabel.text = [arryTableData objectAtIndex:indexPath.row];  
     else if(indexPath.section ==2) 
      cell.textLabel.text = [arryAddressInfo objectAtIndex:indexPath.row]; 
     else if(indexPath.section == 3)   
      cell.textLabel.text = [arryTableActions objectAtIndex:indexPath.row];  
     else if(indexPath.section == 4) 
      cell.textLabel.text = @"REPLACE ME WITH ICONS"; 

     return cell; 
    } 
} 

답변

2

, 당신은을 사용하여 현재 문제의 비디오를 볼 수 있습니다 잘못된 식별자 :

이 결과로 식별자의 경우따라서 식별자가있는 셀을 (섹션 0에서) 묻는다면 실제로 텍스트로만 채워지는 하나의 백을 얻게됩니다.

+0

+1 나를 때려 눕힌다. – Benjie

+0

너는 beut! 고마워, 너무 오랫동안 보았다 – TMB87

+0

하하 문제 없어, 때로는 신선한 눈 쌍이 필요해. –

관련 문제