Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mdeh

macrumors 6502
Original poster
Jan 3, 2009
345
2
Hi all,
I'm stuck :confused:

I have implemented a very basic app. It is based on Chap 7 of Hillegass.
A slider, two textFields, and a couple of buttons. Bascially, the the slider's value, the textField's value are bound to a number(fido) in a userDefined Controller(AppController). This works as expected...the slider causes the textField to update.
The first button initiates KVO in the second textField.

Now, **this** works. ( this is the method in the startKVOButton)
Code:
[ self addObserver:(NSObject *) self forKeyPath:(NSString *) @"fido" 
options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) 
context: @"Starting KVO"];
And is implemented thus;
Code:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
	NSLog(@"keyPath:%@\n Object: %@\n change: %@:", keyPath, object, change);
	if ( [ keyPath isEqual:@"fido"])
		[textField setObjectValue: [change objectForKey: NSKeyValueChangeNewKey]];
	/* NSLog(@"%@", context);  */
	
}


Here is my question. Hillegass seems to imply that one can take an object eg a text field and specify that the text field **alone** register itself as an observer
How did the text field become an observer of the "fido" key.....the text field added itself as an observer."

However, if I try and implement this in the above methods, for example change the line of code from
Code:
self addObserver:(NSObject *) self
to
Code:
self addObserver:(NSObject *) textField
**where textField is an outlet of AppController, suitable linked in IB to the second textField**

I get an error thus
<NSTextField: 0x128ea0>: An -observeValueForKeyPath: ofObject:change:context: message was received but not handled.An -observeValueForKeyPath: ofObject:change:context: message was received but not handled.

Which leads me to ask this.

Is a control in of itself not an object? Or am I trying to do something that is simply not possible?

Thanks in advance.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.