Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 2, 2009, 04:49 PM   #1
mdeh
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)
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
Quote:
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
Quote:
<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

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Battery Question MilkMan4 MacBook Air 2 Jul 25, 2011 10:41 AM
Safari Question! MilkMan4 Mac Applications and Mac App Store 6 Jul 22, 2011 01:51 AM
Flashing Question Mark has me pulling my hair out momech OS X 8 Dec 30, 2010 11:47 PM
Just a Question about Next Gen Macbook Pro (not a whether to buy now or not) macnerd123 MacBook Air 7 Dec 20, 2010 09:48 PM
Flashing question mark folder on startup Penny's Geek OS X 6 Nov 17, 2010 07:38 PM


All times are GMT -5. The time now is 09:57 AM.

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

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