我在第一个视图中有两个视图说A用于保存文档目录中的图像保存按钮单击然后第二个视图说B.我有两个上传该图像与表的特定单元格.在下面的代码我试图比较图像具有特定用户电子邮件id.Email在两个视图中都很常见.因此,我可以将特定用户与他们的电子邮件区分开来,并且在他们的表格视图单元格中,我们以不同的方但我无法做到这一点……如何在
Ios中实现这一目标? AnyOne可以帮助我解决这个问题….我的代码用于保存和加载文档目录中的图像
在此处输入代码
在此处输入代码
查看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); } }
查看B.
- (UIImage*)loadImage { NSLog(@"Email^^^^^^^^^%@",imgEmail); NSError *error; NSFileManager *fileMgr = [NSFileManager defaultManager]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,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; }
解决方法
您可以按照以下修改saveImage和loadImage函数.
-(void)saveImage: (UIImage*)image filePath:(Nsstring*)fileNameEmail { if (image != nil) { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,YES); Nsstring *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:fileNameEmail]; NSData* data = UIImagePNGRepresentation(image); [data writetoFile:filePath atomically:YES]; } } - (UIImage*)loadImage:(Nsstring*)fileNameEmail { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,YES); Nsstring *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:fileNameEmail]; UIImage *image = [[UIImage alloc] initWithContentsOfFile:filePath]; return image; }
编辑:您可以获得如下特定图像.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; cell.youimageview.image = [self loadImage:[[yourArray indexOfObject:indexPath.row] valueForKey:@"youemailkey"]]; return cell; }
这可能对你有所帮助.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。