Apple hereが提供する例を使用して、アプリに画像の遅延読み込みを正常に実装しました。問題は、スクロール中に画像をロードしたいのですが、ドラッグが終了したときにのみ画像がセルにロードされることです(画面から指を離します。それまでセルは空のままです)。次のようにコードを変更しました。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//NSLog(@"cell for row at indexpath, size - %f, current - %d", flowTable.contentSize.height, self.current);
NSString *CellIdentifier = @"FlowCell";
MyFlowCell *cell = (MyFlowCell *)[self.flowTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FlowCell" owner:nil options:nil];
// cell = [nib objectAtIndex:0];
for(id currentObject in nib)
{
if([currentObject isKindOfClass:[MyFlowCell class]])
{
cell = (MyFlowCell *)currentObject;
break;
}
}
}
ImageDetails *rowItem = [self.imageData objectAtIndex:indexPath.row];
if (!rowItem.mainImage)
{
// if (self.flowTable.dragging == NO && self.flowTable.decelerating == NO)
// {
[self startIconDownload:rowItem forIndexPath:indexPath];
//}
cell.mainImage.backgroundColor = [UIColor grayColor];
}
else
{
cell.mainImage.image = rowItem.mainImage;
}
}
return cell;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (!decelerate)
{
// [self loadImagesForOnscreenRows];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//[self loadImagesForOnscreenRows];
}
さらに、私の ImageDownloader クラスでは、画面から指を離すまで NSURLConnection が応答さえ受け取らないことがわかりました。なぜこれが起こっているのかを突き止めようとしていますが、これまでのところ成功していません。何か見逃していたら教えてください。