0

検索に使用できるヘルプまたはキーワードがあれば教えてください。

私の問題は、「UpdateViewController.xib」と呼ばれる1つのUIViewがあり、プログラムで20個の小さな画像とそれらの画像の下のテキストをロードすることです。ユーザーがこれらの画像をクリックすると、「imageSumVuew.xib」と呼ばれるIBによって作成された次のビューに変わり、UpdateViewControllerにリンクするボタンがあります。

#import "imageSumView.h"  // next view that i wanna load//
// the transition to next view
imageSumView *nextView = [[imageSumView alloc]init];
self.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:nextView animated:YES completion:NULL];
[nextView release];

nextView には、このビューに戻るこれに似たコードがあります

#import "UpdateViewController.h"  // old that i wanna load back//
    // the transition to old view
    UpdateViewController *oldView = [[UpdateViewController alloc]init];
    self.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:oldView animated:YES completion:NULL];
    [oldView release];

問題は、それが UpdateViewController にロードされたときに、すべての画像とテキストをもう一度リロードする必要があることです。

問題は、「UpdateViewController ビューのキャッシュを保持するにはどうすればよいですか?」です。選択したい画像を確認するために、このページ間を何度も行き来する必要があるため、ユーザーに画像をもう一度リロードさせたくありません。 .

友達の画像のリストが表示され、最初の友達の写真を確認したい場合は、インスタグラムを考えてみてください。その後、ロードせずに友達の全体像に戻り、2 番目の友達を選択します。

4

1 に答える 1

0

初めてダウンロードしたときに、一意の ID を持つ画像データを一時ディレクトリに保存します。次回は、ディレクトリ内でそのユーザー ID のイメージを確認し、そこにある場合はそこからイメージをロードします。例えば ​​:

#TMP NSTemporaryDirectory() の定義
    NSString *filename=[NSMutableString stringWithFormat:@"userimage_%@",userId];

    NSString *uniquePath = [TMP stringByAppendingPathComponent:ファイル名];
    NSData *dataImage = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]
    UIImage *image = [[UIImage alloc] initWithData: dataImage];
    [UIImageJPEGRepresentation(image, 1.0f) writeToFile: uniquePath アトミック: YES];
    【画像公開】;

あなたのイメージを取得するには、以下のようなことができます:

- (NSData *) getImage: (NSString *)userId
{
    NSString *filename=[NSMutableString stringWithFormat:@"userimage_%@,userId];
    NSString *uniquePath = [TMP stringByAppendingPathComponent: ファイル名];

    if([[NSFileManager defaultManager] fileExistsAtPath: uniquePath])
    {
        return [[NSData alloc] initWithContentsOfFile:uniquePath];
    }
    nil を返します。
 }

于 2012-07-17T05:32:58.873 に答える