0
からイメージをロードする方法を、私は現在、このメソッドを介して私のUIImageViewで画像を保存しています:だから、NSHomeDirectory
- (void)applicationDidEnterBackground:(UIApplication*)application {
NSString *image1 = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image1.png"];
NSString *image2 = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image2.png"];
}
画像がうまく保存するが、私はのviewDidLoadでUIImageViewsの画像を設定する方法が分かりません。これは私が試したことです:
- (void)viewDidLoad
{
self.imageView.image =[UIImage imageNamed:[(NSHomeDirectory *)Documents objectForKey:@"image1"]];
self.imageView2.image =[UIImage imageNamed:[(NSHomeDirectory *)Documents objectForKey:@"image1"]];
}
しかし、明らかにそれは動作していません。私はここで基礎を理解するのに困っている。どんな助けも素晴らしいだろう、ありがとう!
ありがとうございました。したがって、私のviewDidLoadは次のようになります: 'NSString * image1String = [[NSBundle mainBundle] pathForResource:@" Documents/image1 "ofType:@" png "]; ' ' self.imageView = [UIImage imageWithContentsOfFile:image1String]; '?私は、警告 "UIImageからUIImageView *を割り当てる互換性のないポインタ型"を取得しています。 – John
あなたは近くです。 '-imageWithContentsOfFile:'でロードした 'UIImage'から' UIImageView'オブジェクトを作成する必要があります。したがって: 'self.imageView = [[[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imagePath]] autorelease];' –
ありがとうございます! – John