Re: CORE DATA: setImage (transient) and setImageData (binary) accessors don't fire.
Re: CORE DATA: setImage (transient) and setImageData (binary) accessors don't fire.
- Subject: Re: CORE DATA: setImage (transient) and setImageData (binary) accessors don't fire.
- From: mmalcolm crawford <email@hidden>
- Date: Sun, 15 Jan 2006 15:38:47 -0800
On Jan 15, 2006, at 9:49 AM, Frederick C. Lee wrote:
So the question is, how does NSManagedObject effect binary
accessors differently from strings??
It doesn't.
[AppDelegate] -->> [RegionArrayController -->> [MapArrayController]
--->> NSImageView GUI. *problem*
...appears to be a bug: too complicated for binding.
It is almost certainly a bug in your set-up.
You seem to be making this extraordinarily complicated.
Please, just create a simple project with a single Entity, Person.
Add two attributes:
name: String
imageData: Binary
If you want, create a custom class for the entity (directly from
Xcode using the New File menu item), and put a log statement in the
setImage: method. In the subsequent test, it *will* be called.
Now "auto-create" an interface for Many Objects. Amongst other
things, you get an image view, properly configured for the image
attribute for the selected Person object.
You should get a complete working application that allows you to add
Person objects, give them names, and drop images into the image view.
Check the bindings for the image view, and make sure your interface
matches.
If you really need to store a separate NSImage, then to the Person
entity add another attribute,
nsImage: Undefined (Transient).
Then implement the accessor methods etc. as shown in the Core Data
Programming Guide (see below).
Finally, change the binding of the image view:
(1) Unbind 'data'.
(2) Bind 'value' to [Person Array Controller].selection.nsImage
mmalc
- (NSImage *)nsImage;
{
[self willAccessValueForKey:@"nsImage"];
NSImage *image = [self primitiveValueForKey:@"nsImage"];
[self didAccessValueForKey:@"nsImage"];
if (image == nil) {
NSData *imageData = [self valueForKey:@"imageData"];
if (imageData != nil) {
image = [[[NSImage alloc] initWithData:imageData]
autorelease];
[self setPrimitiveValue:image forKey:@"nsImage"];
}
}
return image;
}
- (void)setNsImage:(NSImage *)value
{
[self willChangeValueForKey: @"nsImage"];
[self setPrimitiveValue: value forKey: @"nsImage"];
[self didChangeValueForKey: @"nsImage"];
}
- (void)willSave
{
NSImage *image = [self primitiveValueForKey:@"nsImage"];
if (image != nil) {
[self setPrimitiveValue:[image TIFFRepresentation]
forKey:@"imageData"];
}
else {
[self setPrimitiveValue:nil forKey:@"imageData"];
}
[super willSave];
}
(Note: This assumes that you will always access the image using the
NSImage object. If you change the image object, the NSData object is
not synchnronised until save time.)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden