ios - 从 NSData 检索图像

标签 ios iphone nsdata

我有一个 View Controller ,允许我添加名称、图像和日期。名称和日期被发送回 TableView Controller 并显示。然后我有一个编辑 View Controller ,当填充时显示单元格被单击...

我的保存方法:

-(IBAction)save:(id)sender {
  NSData *imageData = UIImagePNGRepresentation(_imageview.image);
  [self.currentPlayer setValue:imageData forkey:@"playerPic"];

 [self.delegate addPlayerViewControllerDidSave];
} 

我的代表正在调用保存:&错误所以我不会粘贴该代码

我相信这是可行的,但我的问题是如何在编辑 View Controller 上显示该图像

我的姓名和日期信息已通过,但图片未通过

我有一个 UIImageView,我正在尝试类似的东西,但我知道这是两种不同的指针类型,不会起作用

 -(void)viewDidLoad {
 firstnameTextField.text = [self.currentPlayer playerName];
 editImage.image = [self.currentPlayer playerPic];

 }

任何帮助将不胜感激

最佳答案

您需要从 NSData 对象创建一个 UIImage,如下所示:

[UIImage imageWithData:[self.currentPlayer playerPic]]

关于ios - 从 NSData 检索图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21419303/

相关文章:

ios - 当应用程序在后台运行时,iOS 会删除 NSTemporaryDirectory 文件吗

ios - 如何在 Objective-C iOS 中迭代和设置类的属性

iphone - 在 Xcode 中设置图像 mask 的颜色

ios - 如何在本地存储 NSData

ios - 如何将 Objective-C NSError 指针传递给 Swift 函数?

ios - 当Int溢出导致IOS app crash时,如何remark

iphone - 更新 iPhone 4 Retina 显示屏的应用程序

iphone - 如何在 Landscape 而不是 Portrait 中显示 UIImagePickerControllerSourceTypeCamera

xcode - Swift - 从 userDefaults 保存和检索图像

swift - 将 4 个字节的 (Swift3) 数据放入 UInt32 的两种方法