即时通讯使用异步块(大中央调度)加载我的细胞图像。但是,如果您快速滚动,它们仍会以非常快的速度出现,直到它加载了正确的一个。我确定这是一个普遍的问题,但我似乎无法找到它。tableView细胞图像异步加载闪烁快速滚动
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Load the image with an GCD block executed in another thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[[appDelegate offersFeeds] objectAtIndex:indexPath.row] imageurl]]];
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *offersImage = [UIImage imageWithData:data];
cell.imageView.image = offersImage;
});
});
cell.textLabel.text = [[[appDelegate offersFeeds] objectAtIndex:indexPath.row] title];
cell.detailTextLabel.text = [[[appDelegate offersFeeds] objectAtIndex:indexPath.row] subtitle];
return cell;
}
请参阅http://stackoverflow.com/questions/19326284/what-is-the-proper-way-to-use-nscache-with-dispatch-async-in-a-reusable-table-ce/19327472# 19327472或http://stackoverflow.com/questions/16663618/async-image-loading-from-url-inside-a-uitableview-cell-image-changes-to-wrong/16663759#16663759 – Rob
请考虑我的帖子http ://stackoverflow.com/a/26147814/3052059。谢谢! –
我会推荐阅读这篇博文http://www.natashatherobot.com/how-to-download-images-asynchronously-and-make-your-uitableview-scroll-fast-in-ios/ – pprochazka72