0

アドホック更新後にアプリのドキュメントフォルダから既存の画像を読み込む際に問題が発生します。

インターネットで回答を検索しましたが、アプリの更新時にパスを同じに保つには、ファイルへの相対パスを使用する必要があることがわかりました。

誰かがそれを行う方法を教えてもらえますか?

現在、ImagePickerが終了したときにファイル(画像)を保存するために以下を使用しています。

NSString *imageFilename = [NSString stringWithFormat:@"%@-profilePhoto.jpg",[NSDate date]];
NSArray *paths = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

imagePath = [NSString stringWithFormat:@"%@/%@", paths, imageFilename];

私を助けてください !

4

2 に答える 2

1

私は解決策を見つけました:

フルパスから画像をロードする代わりに、システムで名前の後に画像を検索するようにしました。

したがって、代わりに:

//Full path stored in a dictionary:
    profilePhotoPath = [userDict objectForKey:@"profilepic"];
//Load the image from path:
    profilePhoto = [[UIImage alloc] initWithContentsOfFile:profilePhotoPath];

私は今、以下を使用しています:

//Load image from documentsDirectory, filename
    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    profilePhotoPath = [userDict objectForKey:@"profilepic"];
    profilePhotoPath = [documentsDirectory stringByAppendingPathComponent:[profilePhotoPath lastPathComponent]];
    profilePhoto = [[UIImage alloc] initWithContentsOfFile:profilePhotoPath];

「lastPathComponent」属性を使用することで、基本的にファイル名を除くすべてのパスを削除し、NSSearchを使用してファイルを取得します。

于 2012-10-20T11:26:12.310 に答える
0

この行は問題を引き起こします

NSArray *paths = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

ここでの問題は、可変パスがタイプでNSArrayはないことですNSString

に変更して、

NSString *paths = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

また

NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *paths = [path objectAtIndex:0];
于 2012-10-20T09:51:40.650 に答える