我的TableView的每个单元格都包含UIImage,我做了一个动作来更改每个单元格中UIImage中的所有图像,然后重新加载表格。
在我滚动表格之前,图像没有改变
我知道TableView在滚动期间正在加载单元格
但有没有办法解决我的问题?
由于
答案 0 :(得分:1)
确保从MainThread中呼叫reloadData
或beingUpdates
/ endUpdates
。您可以通过以下方式查看:
if (![NSThread mainThread]) {
return;
}
这是一个例子。 ViewController是ImageDownloader的委托,当图像下载完成后,它会调用-acceptImage,然后在主线程上执行选择器以执行表更新。另请参阅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];
}
答案 1 :(得分:0)
您是否致电[tableView reloadData];
?