我正在尝试从文档目录加载UIImage
,并将其设置为UIImageView
,如下所示:
NSString *pngfile = [[MyUtil getLocalDirectory] stringByAppendingPathComponent:@"school.png"];
NSLog(@"%@", pngfile);
if ([[NSFileManager defaultManager] fileExistsAtPath:pngfile]) {
NSData *imageData = [NSData dataWithContentsOfFile:pngfile];
UIImage *img = [UIImage imageWithData:imageData];
[schoolImage setImage:img];
}
但是,无论我如何尝试上述方法,图像都无法加载。该图像位于Documents/MyAppCustomDirectory/school.png
中。使用上述方法从该目录加载是否正确?
我还尝试了其他几种方法,如基于SO响应的UIImage imageWithContentsOfFile
等方式。
MyUtil getLocalDirectory
的代码。 - rmaddy