Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread Display Modes
Old Jul 2, 2009, 04:49 PM   #1
macrumors 6502
Join Date: Jan 2009
addObserver: forKeyPath:options: question

Hi all,
I'm stuck

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)
[ self addObserver:(NSObject *) self forKeyPath:(NSString *) @"fido" 
context: @"Starting KVO"];
And is implemented thus;
- (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
self addObserver:(NSObject *) self
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.

Last edited by mdeh; Jul 2, 2009 at 05:08 PM.
mdeh is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Carrier: Question - LTE Availability Options jeme iPad 5 Nov 14, 2013 10:22 AM
Mac OSX startup options. Curious question bigpoppamac31 OS X 10.8 Mountain Lion 1 Oct 30, 2013 11:38 AM
New iMac RAM options question washburn iMac 2 Nov 19, 2012 05:06 PM
HD Erase Options question James Godfrey Mac OS X 10.7 Lion 4 Jul 10, 2012 08:50 AM
Question: Dual TB Display Options For My iMac dmax35 iMac 1 Jul 10, 2012 08:18 AM

Forum Jump

All times are GMT -5. The time now is 12:34 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2015, MacRumors.com, LLC