こんにちは私はGCDを使用してuitableviewに画像をロードしています。さて、問題は画像アニメーションです。セルに読み込まれるサーバーから3つの画像を呼び出しましたが、3つの問題が発生しました
1)3つのセルすべてで単一の画像が繰り返されます
2)最初と最後の細胞画像が点滅して変化する
3)画像が変化すると、すべてのセルで繰り返されます。
私はアニメーションを与えましたが、それでもアニメーションはありません。つまり、点滅します。
コード:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
[imageArray retain];
//get a dispatch queue
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//this will start the image loading in bg
dispatch_async(concurrentQueue, ^{
NSData *image = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[imageArray objectAtIndex:indexPath.row]]];
//this will set the image when loading is finished
dispatch_async(dispatch_get_main_queue(), ^{
cell.imageView.image = [UIImage imageWithData:image];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
});
});
return cell;
}