Ios Can';t从iPhone文档目录位置中保存的文件重新加载UIImage

Ios Can';t从iPhone文档目录位置中保存的文件重新加载UIImage,ios,iphone,objective-c,uiimage,Ios,Iphone,Objective C,Uiimage,我正在制作一个应用程序,将文件保存到iPhones文档目录,然后当视图控制器重新加载时,它将从同一位置获取并显示它。但它并不是获取并显示它 我正在使用以下方法保存图像: void UIImageWriteToFile(UIImage *image, NSString *fileName) { NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)

我正在制作一个应用程序,将文件保存到iPhones文档目录,然后当视图控制器重新加载时,它将从同一位置获取并显示它。但它并不是获取并显示它

我正在使用以下方法保存图像:

void UIImageWriteToFile(UIImage *image, NSString *fileName)
{
    NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectoryPath = dirPaths[0];
    NSString *filePath = [documentDirectoryPath stringByAppendingPathComponent:fileName];

    NSData *imageData = UIImagePNGRepresentation(image);
    [imageData writeToFile:filePath atomically:YES];
}
我试图使用以下代码从viewDidLoad方法中调用保存的图像:

    NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectoryPath = dirPaths[0];

    NSString *fileName = [NSString stringWithFormat:@"/%@.png", self.fullname.text];

    NSString *filePath = [documentDirectoryPath stringByAppendingString:fileName];
    [self.imageView setImage:[UIImage imageNamed: filePath]];

但是,它没有显示我的图像。谁能帮我一下,告诉我哪里出了问题。我是iOS开发新手。

替换这一行:
[self.imageView setImage:[UIImage-imagename:filePath]

关于这一点:

UIImage *image = [[UIImage alloc] initWithContentsOfFile:filePath];
[self.imageView setImage:image];

替换此行:
[self.imageView setImage:[UIImage ImageName:filePath]]

关于这一点:

UIImage *image = [[UIImage alloc] initWithContentsOfFile:filePath];
[self.imageView setImage:image];

你需要使用这个方法

- (UIImage*)initWithContentsOfFile:(NSString*)path
从文档或缓存目录初始化图像


ImageName:用于从应用程序包获取图像。

您需要使用方法

- (UIImage*)initWithContentsOfFile:(NSString*)path
从文档或缓存目录初始化图像


ImageName:用于从应用程序包获取图像。

您可以将
[UIImage ImageName::
用于文档文件夹中的图像,并具有基础缓存机制的优点,但文件路径略有不同

使用以下命令:

 NSString *fileName = [NSString stringWithFormat:@"../Documents/%@.png", self.fullname.text];
 UIImage *image = [UIImage imageNamed:fileName];

您可以对文档文件夹中的图像使用
[UIImage imageNamed::
,并具有底层缓存机制的优点,但文件路径略有不同

使用以下命令:

 NSString *fileName = [NSString stringWithFormat:@"../Documents/%@.png", self.fullname.text];
 UIImage *image = [UIImage imageNamed:fileName];

成功了!非常感谢。但出于某种原因,它会将图像逆时针加载90度。你知道这是为什么吗?另外,我如何将其旋转回正常视图?self.imageView.image.imageOrientationThat worked!非常感谢。但出于某种原因,它会将图像逆时针加载90度。你知道这是为什么吗?另外,如何将其旋转回正常视图?self.imageView.image.imageOrientation