在第一个视图中,我们有一个名为A的按钮,点击可以将图片保存到文档目录中,然后我们有第二个视图B。我们需要在表格的特定单元格上传这张图片。在下面的代码中,我试图根据用户电子邮件地址来比较图片。在两个视图中,电子邮件是共同的。我该如何区分不同用户并在他们的表格视图单元格上以不同的方式显示他们的图片呢?但我无法做到这一点....如何在iOS中实现?请帮忙解决...我想分享一下我用于在文档目录中保存和加载图像的代码:
enter code here
视图A:
-(void)saveImage: (UIImage*)image
{
if (image != nil)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:
@"iosImage.png" ];
NSString *fileName = [path stringByAppendingFormat:email];
NSLog(@"The result of Concatenate String =%@",fileName);
NSData* data = UIImagePNGRepresentation(image);
[data writeToFile:path atomically:YES];
NSLog(@"The Path of the directory %@",path);
}
}
View B
- (UIImage*)loadImage
{
NSLog(@"Email^^^^^^^^^%@",imgEmail);
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:
@"iosImage.png" ];
UIImage* image = [UIImage imageWithContentsOfFile:path];
NSLog(@"Documents directory: %@",[fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
return image;
}