2011-11-06 2 views
0
[self.countryList reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:6 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone]; // or NO ;) 

내 문제는 내가보기에 단지 6 셀 10 개 + 항목과의 tableview이 있지만 데이터가로드되는 테이블이 스크롤 될 때 세포 (7)에 데이터가없는 것입니다 그것. 해당 셀의 데이터를 어떻게 다시로드 할 수 있습니까?다시로드 jQuery과 데이터

위 코드는 제가 사용하고있는 것이며 작동하지 않습니다!

EDIT --- --- 이것은 일반적 cellForRowAtIndexPath:의 재활용/재사용기구의 오용

if (cell == nil) { 

    cell =[[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:identifier]autorelease]; 
    //[cell setBackgroundColor: [UIColor clearColor]]; 




    mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(52.0, 0.0, 200.0, 20.0)] autorelease];   
    mainLabel.tag = 1;   
    mainLabel.font = [UIFont systemFontOfSize:14.0];    
    mainLabel.textAlignment = UITextAlignmentLeft;   
    mainLabel.textColor = [UIColor blackColor]; 
    mainLabel.opaque = YES; 
    mainLabel.backgroundColor=[UIColor clearColor]; 
    [cell.contentView addSubview:mainLabel]; 

    revenue = [[[UILabel alloc] initWithFrame:CGRectMake(52.0, 20.0, 150.0, 20.0)] autorelease];    
    revenue.tag = 3;    
    revenue.font = [UIFont systemFontOfSize:14.0];   
    revenue.textAlignment = UITextAlignmentLeft;    
    revenue.textColor = [UIColor blackColor]; 
    revenue.opaque = YES; 
    revenue.backgroundColor=[UIColor clearColor]; 
    [cell.contentView addSubview:revenue]; 

    promos = [[[UILabel alloc] initWithFrame:CGRectMake(252.0, 20.0, 150.0, 20.0)] autorelease];    
    promos.tag = 4;   
    promos.font = [UIFont systemFontOfSize:14.0];   
    promos.textAlignment = UITextAlignmentLeft;   
    promos.textColor = [UIColor blackColor]; 
    promos.opaque = YES; 
    promos.backgroundColor=[UIColor clearColor]; 
    [cell.contentView addSubview:promos]; 

    updates = [[[UILabel alloc] initWithFrame:CGRectMake(252.0, 0.0, 200.0, 20.0)] autorelease];    
    updates.tag = 5;    
    updates.font = [UIFont systemFontOfSize:14.0];   
    updates.textAlignment = UITextAlignmentLeft;    
    updates.textColor = [UIColor blackColor]; 
    updates.opaque = YES; 
    updates.backgroundColor=[UIColor clearColor]; 
    [cell.contentView addSubview:updates]; 

    photo = [[[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 50.0, 50.0)] autorelease]; 
    photo.contentMode= UIViewContentModeScaleToFill; 
    photo.tag = 2; 
    photo.opaque = YES; 
    photo.backgroundColor=[UIColor clearColor]; 
    [cell.contentView addSubview:photo]; 

}  
else { 
    cell.clearsContextBeforeDrawing=YES; 
    mainLabel = (UILabel *)[cell.contentView viewWithTag:1];  
    photo = (UIImageView *)[cell.contentView viewWithTag:2]; 
    promos=(UILabel *)[cell.contentView viewWithTag:4]; 
    revenue=(UILabel *)[cell.contentView viewWithTag:3]; 
    updates=(UILabel *)[cell.contentView viewWithTag:5]; 


    if(photo.image){ 
     photo.image=nil; 
    } 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *imageURL =[NSString stringWithString:[(arrayResults*)[tweets objectAtIndex:indexPath.row] myCountryIcon]]; 

    NSArray *myArray = [imageURL componentsSeparatedByString: @"/"]; 
    NSString *fileName = [NSString stringWithString:[myArray lastObject]]; 
    NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/AppIcons"]; 
    NSString* path = [dataPath stringByAppendingPathComponent:fileName]; 
    UIImage* image = [UIImage imageWithContentsOfFile:path]; 
    if (!image) { 

     UIApplication* app = [UIApplication sharedApplication]; 
     app.networkActivityIndicatorVisible = YES; 
     // Create an array with the URL and name. 
     NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:fileName,imageURL, nil ]; 


     [self performSelectorInBackground:@selector(loadImageInBackground:) withObject:arr]; 
     [arr release]; 


    }    
    else{ 
     photo.image=image; 


    } 
    NSString*promostext=[[NSString alloc] initWithFormat:@"promos:%@",[[(arrayResults*)[tweets objectAtIndex:indexPath.row] mypromos]stringValue] ]; 
    NSString*revenuetext=[[NSString alloc] initWithFormat:@"revenue:%@",[(arrayResults*)[tweets objectAtIndex:indexPath.row] myrevenue] ]; 
    NSString*updatestext=[[NSString alloc] initWithFormat:@"updates:%@",[[(arrayResults*)[tweets objectAtIndex:indexPath.row] myupdates]stringValue] ]; 

    mainLabel.text=[(arrayResults*)[tweets objectAtIndex:indexPath.row] myCountryName]; 
    promos.text=promostext; 
    revenue.text=revenuetext; 
    updates.text=updatestext; 
    [promostext release]; 
    [revenuetext release]; 
    [updatestext release]; 

} 
+0

tableView : cellForRowAtIndexPath : 여기에 문제가있는 것 같습니다. 코드를 게시 할 수 있습니까? –

+0

위에 추가했습니다. – d4ndym1k3

+0

나머지는 어떻게됩니까? 실제로 라벨에 텍스트를 넣고 이미지보기에 이미지를 넣으시겠습니까? – jrturton

답변

1

.

너무 많은 UITableViewCell을 할당하지 않도록 스크롤 할 때 셀을 다시 사용합니다. 따라서 셀이 할당 된 경우 (cell == nil) 또는 셀이 재사용 된 경우 (cell! = nil) 두 경우 모두에서 셀의 내용을 cellForRowAtIndexPath:으로 설정해야합니다.

+0

그러면 셀 1-6과 8-10이로드되고 7이 아닌 이유는 무엇입니까? 나는 다른 앱에서 같은 코드를 사용하고 있는데이 문제가 없다고 덧붙여 야합니다. – d4ndym1k3

+0

제가 설명한 이유와 정확히 같습니다. 이 첫 번째 셀은 할당되고'cell == nil' 경우에 내용을 채 웁니다 (이미 할당 된 있지만 사용되지 않고 재사용 할 수있는 기존 UITableViewCell이 없기 때문에'dequeueCellWithIdentifier'는'nil'을 반환합니다).하지만 스크롤하면 해당 셀은 다른 내용을 표시하기 위해 재사용 (재활용)되므로 여기에 코드에 문제가있는 'cell! = nil' 사례가 있습니다. 두 경우 모두 코드에서 어떤 경로가 실행되는지 정확하게 이해하려면 코드에 중단 점을 넣으십시오. – AliSoftware

+0

특히 레이블, 이미지 뷰, 기타 ​​(한 셀과 다른 셀 사이에서 변경되는 모든 것)의 내용을 채워야합니다. ** 두 가지 경우 모두 셀을 채우기 위해 ** if 문 외부에서 ** 이들 셀은 재활용되었습니다 또는 방금 할당되었습니다. – AliSoftware