UITableView
からいくつかの画像をロードするアプリに がありますNSDocumentDirectory
。それは機能しますが、上下にスクロールすると、アプリが少しフリーズするように見えます。これは、おそらくメインスレッドで画像が提供されているためであり、ロードされるまで tableView のスクロールを効果的にブロックします。私の問題は、スクロール中に後でそれらをロードする方法がわからないことです。これは「遅延ロード」機能です。
これは、画像をロードするために使用されるコード スニペットです。
imagesPath = [NSString stringWithFormat:@"%@/images/", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
if ([fileManager fileExistsAtPath:[imagesPath stringByAppendingPathComponent:[NSString stringWithFormat:@"/%d.png", rowID]]]) {
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[imagesPath stringByAppendingPathComponent:[NSString stringWithFormat:@"/%d.png", rowID]]];
// If image contains anything, set cellImage to image. If image is empty, use default, noimage.png.
if (image != nil){
// If image != nil, set cellImage to that image
cell.cellImage.image = image;
}
[image release];
}
スクロールの遅れを避けるために、各セルの画像を「遅延ロード」する最良の方法は何ですか?