2011-09-08 11 views
0

내 TableView의 각 셀에 UIImage가 포함되어 있습니다. 각 셀의 UIImage에서 모든 이미지를 변경 한 다음 테이블을 다시로드하는 작업을 수행했습니다.
이미지를 스크롤 할 때까지 이미지가 변경되지 않았습니다.
TableView가 스크롤하는 동안 셀을로드한다는 것을 알고 있습니다.
하지만 문제를 해결할 수있는 방법이 있습니까?TableView 다시로드 문제

감사

+0

아마 여기에 귀하의 코드를 게시 할 수 있습니다 .. 그리고 내가 게으른 로딩 이미지 또는 기본 하나를 사용할지 여부를 알아야합니다. – sicKo

답변

1

당신이 MainThread에서 reloadData 또는 beingUpdates/endUpdates를 호출해야합니다. 다음을 통해 확인할 수 있습니다.

if (![NSThread mainThread]) { 
    return; 
} 

다음은 예제입니다. ViewController는 ImageDownloader의 위임자이며 이미지 다운로드가 완료되면 -acceptImage라는 다운로드를 실행 한 다음 주 스레드에서 선택기를 실행하여 테이블 업데이트를 수행합니다. 당신이 [tableView reloadData];UITableView Reference

- (void)setDownloadedImage:(NSMutableDictionary *)d { 
    UIImageView *imgV = (UIImageView *)[d objectForKey:@"imageView"]; 
    NSIndexPath *indexPath = [d objectForKey:@"userInfo"]; 
    [thumbs addObject:[ImageWorks imageWithImage:[UIImage imageWithData:[d objectForKey:@"image"]] scaledToSize:imgV.frame.size]]; 
    [table beginUpdates]; 
    [table insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationMiddle]; 
    [table endUpdates]; 
    loadingView.hidden = YES; 
} 

- (void)acceptImage:(NSData *)image ForUserInfo:(id)userInfo ForUrl:(NSString *)url { 
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    NSMutableDictionary *d = [[NSMutableDictionary alloc] init]; 
    iPhoneMyTableCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"iPhoneMyTableCell" owner:self options:nil] lastObject]; 
    [d setObject:userInfo forKey:@"userInfo"]; 
    [d setObject:(image ? image : UIImagePNGRepresentation([UIImage imageNamed:@"ImageMissing.png"])) forKey:@"image"]; 
    [d setObject:cell.myImageView forKey:@"imageView"]; 
    [self performSelectorOnMainThread:@selector(setDownloadedImage:) withObject:d waitUntilDone:YES]; 
    [d release]; 
    [pool drain]; 
} 
0

전화 했 또한, 참조?