Reputation: 49
Receiving error: valueForUndefinedKey:]: this class is not key value coding-compliant for the key imgSelect
I have a tableview with that is editable.. When selecting cell, it takes you to edit information. Everything works great, except the image. User can save image, image is displayed in tableview, but when going back to edit, it crashes. Here is the poorly written code:
without trying to reload the image to edit, everything else works. The image is saved to database and is displayed in tableview..
var existingItem: NSManagedObject!
override func viewDidLoad() {
super.viewDidLoad()
// Reload data to edit
if existingItem {
txtPTitle.text = project
txtPDesc.text = desc
txtSDate.text = sdate
txtEDate.text = edate
}
but when I add the following to load image when editing tablecell
// Reload data back into form
if existingItem {
txtPTitle.text = project
txtPDesc.text = desc
txtSDate.text = sdate
txtEDate.text = edate
var data: NSManagedObject = NSManagedObject()
let imageData:NSData = data.valueForKeyPath("projectImage") as NSData
let projectImage:UIImage = UIImage(data: imageData)
println("we have an image")
imgSelect.image = projectImage
}
it crashes with the following error.
'NSUnknownKeyException', reason: '[<_NSZeroData 0x7fe7f1c3b020> valueForUndefinedKey:]: this class is not key value coding-compliant for the key imgSelect.'
Upvotes: 2
Views: 3723
Reputation: 299633
I would suspect that you haven't actually bound imgSelect
in Interface Builder.
Does it actually crash at the imgSelect.image = projectImage
line, or perhaps earlier (such as during NIB loading)? Is imgSelect
correctly? In either beta 4 or beta 5, they changed the way IBOutlets are defined, and you should make sure you've done a complete clean and rebuild since then (otherwise you could wind up with the wrong object, as you're seeing).
Upvotes: 1