我正在开发一个从 View Controller (字典)保存到文档目录中的 TableView 的应用程序,我在 View Controller 中添加了一个打开 UIImage 的按钮,我还添加了一个 UIImage View 。 我如何保存选择的图像,下面是我的代码,感谢您的帮助。
@IBAction func saveNote(sender: AnyObject) {
if self.txtTitle.text.isEmpty {
println("No title for was typed.")
return
}
var noteDict = ["title": self.txtTitle.text, "body": self.tvBody.text]
var dataArray: NSMutableArray
if appDelegate.checkIfDataFileExists() {
dataArray = NSMutableArray(contentsOfFile: appDelegate.getPathOfDataFile())
dataArray.addObject(Dict)
}
else{
dataArray = NSMutableArray(object: Dict)
}
dataArray.writeToFile(appDelegate.getPathOfDataFile(), atomically: true)
self.navigationController!.popViewControllerAnimated(true)
}
最佳答案
我认为您想要保存图像而不是 ImageView 本身。您可以访问 ImageView 上的图像属性以获取对图像的引用。
我会使用 UIImagePNGRepresentation() 将图像转换为 nsdata,然后将其写入文件系统,并将 url 保存到字典中的图像数据。
图片转数据引用:
关于ios - 将 UIImage View 保存到 SWIFT 字典中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28729818/