Re: Controller Layer and Automatic Key-Value Observing
Re: Controller Layer and Automatic Key-Value Observing
- Subject: Re: Controller Layer and Automatic Key-Value Observing
- From: Frank Illenberger <email@hidden>
- Date: Sat, 8 Nov 2003 01:12:04 +0100
Thank you Henrik,
you helped my a lot. One problem was that I mistook "takeValueForKey"
with "setValueForKey" (did to much EOF lately...) The latter really
triggers an automatic update.
But Apple's online key-value observing documentation
(
http://developer.apple.com/documentation/Cocoa/Conceptual/
KeyValueObserving/index.html) states that direct assignments to
instance variables also should trigger an update:
Listing 3-1 Methods of invoking key-value observing
...
// assigning an instance variable directly
name=[newSavingsName retain];
Is this a bug or is it not yet implemented? Nevertheless, I can't
imagine how they could make this magic work with direct assignments.
Frank Illenberger
Am 08.11.2003 um 00:57 schrieb Henrik Wittland:
>
>
Am 07.11.2003 um 23:41 schrieb Frank Illenberger:
>
>
> Has anybody successfully managed to use the automatic key-value
>
> observing with attributes that are bound in IB???
>
>
>
YES
>
>
> I constructed bindings between attributes in my NSDocument and some
>
> NSTextFields. I assumed that any programmatic changes to my model
>
> variables via set-methods, direct assignments or takeValueForKey calls
>
> should trigger the appropriate updates in the bound TextFields, but
>
> this is not the case.
>
>
If you have a string property named "info" you can do this:
>
>
[self willChangeValueForKey:@"info"];
>
[info autorelease];
>
info = [[[NSCalendarDate calendarDate] description] retain];
>
[self didChangeValueForKey:@"info"];
>
>
or this :
>
>
[self setValue:[[NSCalendarDate calendarDate] description]
>
forKey:@"info"];
>
>
or this :
>
>
-(NSString *)info {return info;}
>
-(void)setInfo:(NSString *)_info {[info autorelease];info = [_info
>
retain];}
>
>
[self setInfo:[[NSCalendarDate calendarDate] description]];
>
>
but not this :
>
>
[self takeValue:[[NSCalendarDate calendarDate] description]
>
forKey:@"info"];
>
>
and not this :
>
>
[info autorelease];
>
info = [[[NSCalendarDate calendarDate] description] retain];
>
>
Direct assignments of ivars realy do not work.
>
takeValue:forKey: does not work and is deprecated.
>
>
> I always have to manually call willChangeValueForKey /
>
> didChangeValueForKey for the controller to recognize the changes.
>
>
You have not used any controller in your example. Bindings from
>
NSTextFields to the
>
File's Owner dont use any NSController. :-)
>
>
Regards,
>
Henrik
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.