1

私のアプリケーションの機能の 1 つは、ユーザーが画像を保存できるようにすることです。これらの画像は、後で UITableView の詳細ビューと UITableView のセルに表示されます。ただし、セルを表示しているページに戻ると、ロードに非常に時間がかかります。これは、画像がドキュメント ディレクトリに保存され、ページが読み込まれるたびにディレクトリから再読み込みされるためだと思います。アプリケーションが起動するたびに画像をメモリにロードして保存する必要がありますか、それとも私の理論から外れているのでしょうか。また、次のコードで画像を圧縮しようとしましたが、パフォーマンスは向上しませんでした。

       [[GTImageStore sharedStore] setImage:currentImage forKey:currentImageKey];

        NSString *jpgName = [[NSString alloc] initWithFormat:@"Documents/%@.jpg", currentImageKey];
        NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:jpgName];

        float scale;
        if (currentImage.size.width < currentImage.size.height)
        {
            scale = 100/currentImage.size.width;
        }
        else if (currentImage.size.width > currentImage.size.height)
        {
            scale = 100/currentImage.size.height;
        }
        else
        {
            scale = 100/currentImage.size.width;
        }

        UIImage *image = [[UIImage alloc] initWithCGImage:currentImage.CGImage scale:scale orientation:[currentImage imageOrientation]];

        [UIImageJPEGRepresentation(image, 0.5) writeToFile:jpgPath atomically:YES];

どんな助けでも本当に感謝しています! ありがとうございました!

セルを追加するためのコード: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UINib *giftCell = [UINib nibWithNibName:@"GiftCell" bundle:nil]; [tableView registerNib:giftCell forCellReuseIdentifier:@"UIGiftsTableCell"];

cell = [tableView dequeueReusableCellWithIdentifier:@"UIGiftsTableCell"];
if (!cell) {
    cell = [[GTGiftCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"UIGiftsTableCell"];
}

// Determine gift at index path
GTGift *gift = (GTGift *)[[[GTGiftStore sharedStore] allGifts] objectAtIndex:[indexPath row]];

[[cell textLabel] setText:[gift name]];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterLongStyle];
NSString *subText = [[NSString alloc] initWithFormat:@"Purchased on %@", [formatter stringFromDate:[gift datePurchased]]];
[[cell subTextLabel] setText:subText];

[[cell detailTopTextLabel] setText:[[gift givingTo] name]];
[[cell detailMiddleTextLabel] setText:[[gift reasonFor] name]];
[[cell detailBottomTextLabel] setText:[[gift boughtFrom] name]];

NSString *jpgName = [[NSString alloc] initWithFormat:@"Documents/%@.jpg", [gift imageKey]];
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:jpgName];
UIImage *imageToLoad = [[UIImage alloc] initWithContentsOfFile:jpgPath];
[[[cell image] layer] setBorderColor:[[UIColor lightGrayColor] CGColor]];
[[[cell image] layer] setBorderWidth:1];
[[cell image] setClipsToBounds:YES];
[[cell image] setContentMode:UIViewContentModeScaleAspectFill];
[[cell image] setImage:imageToLoad];

return cell;

}

GTGiftCell という名前の viewController を持つ xib ファイルを使用して、カスタム セルを作成しました。

4

1 に答える 1

0

あなたが取ることができる2つのアプローチがあります

  1. アプリケーションが変更時に画像をロードする必要がある場合は、そのまま画像をロードし続けますが、ユーザーがビューを更新せずに画像を更新および変更する必要がある場合は、 apples ConcurrencyProgrammingGuideを読んでパフォーマンスを向上させる必要があります。
  2. アプリケーションのロード時に画像をロードしますが、パフォーマンスを向上させるために、同時実行プログラミングガイドをもう一度お読みください
于 2012-05-23T01:46:11.760 に答える