取得した RSS を動的に表示する UITableView があります。RSS をカスタマイズして画像名を返すようにしました。これにより、後ですべてのセルの横に画像を表示するテーブル内のすべてのセルに UIImageView を追加できます。画像の追加
UIImageView *imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(0, 0, 40, 40);
NSString *path = [NSString stringWithFormat:@"URL/%@",object.imageName]; //"object" is the returned Object from the RSS, so basically what i am doing is appending the image name to the path url.
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
imageView.image = [UIImage imageWithData:data];
[cell addSubview:imageView];
[cell bringSubviewToFront:imageView];
そのため、アプリを実行すると、アプリの実行が遅くなり、短時間停止することさえあります。その理由は、この行で直接イメージ化されたすべての RSS を読み込んでいるためです。NSData *data = [NSData dataWithContentsOfURL:url];
この問題の解決策はありますか?
前もって感謝します
私は実際には別のスレッドで画像を取得することを考えていましたが、
dispatch_queue_t fetchImage = dispatch_queue_create("Fetching Image", NULL);
dispatch_async(fetchImage, ^{
NSData *data = [NSData dataWithContentsOfURL:url];
});
dispatch_release(fetchImage);
しかし、そうすると、変数「データ」をキューの外で使用できなくなります。何か案が ?