0

所以,我目前正在通过这种方法将图像保存在我的 UIImageView 中:

- (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"]];
}

但是,显然这是行不通的。我无法理解这里的基础知识。任何帮助都会很棒,谢谢!

4

1 回答 1

3

-imageNamed:如果命名图像尚未被缓存,该方法会在应用程序的主包中查找。从文档:

文件的名称。如果这是第一次加载图像,该方法会在应用程序的主包中查找具有指定名称的图像。

(参见UIImage 类参考

你想要-imageWithContentsOfFile:

于 2012-04-11T19:06:39.627 回答