我使用圖像選擇器從本地設備庫中選取圖像,但是一旦圖庫被使用xcode核心數據解散,圖像就不會保存並顯示在表格視圖單元格中7.3,ios9快捷的2.2如何使用核心數據更新表格視圖單元格中的圖像
if isUpdate == true{
print("object id \(self.store?.objectID)")
self.store?.sName = name.text
self.store?.sDescription = desc.text
//save.setTitle("my text here", forState: .Normal)
let img = UIImage(named: "image.jpeg")
let imgData = UIImageJPEGRepresentation(img!,1)
self.store?.sImage = imgData
do {
try appdelegate.managedObjectContext.save()
self.navigationController?.popViewControllerAnimated(true)
} catch let error as NSError {
print("Could not save \(error), \(error.userInfo)")
}
}else{
//get the description of the entity
let storeDescription = NSEntityDescription.entityForName("Store",inManagedObjectContext: appdelegate.managedObjectContext)
//we create managed object to be inserted to core data
let store = EventsandnotesStore(entity : storeDescription!,insertIntoManagedObjectContext:appdelegate.managedObjectContext)
store.sName = name.text
store.sDescription = desc.text
//
let img = UIImage(named: "image.jpeg")
let imgData = UIImageJPEGRepresentation(img!,1)
store.sImage = imgData
do {
try appdelegate.managedObjectContext.save()
self.navigationController?.popViewControllerAnimated(true)
} catch let error as NSError {
print("Could not save \(error), \(error.userInfo)")
}
}
}
我不小心給了不同的圖像相同的名字,通過使用logError來修復它。 –
很高興解決 –