• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Implementing KVO in a custom view, what to do in observeValueForKeyPath:...?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Implementing KVO in a custom view, what to do in observeValueForKeyPath:...?


  • Subject: Implementing KVO in a custom view, what to do in observeValueForKeyPath:...?
  • From: "Sean McBride" <email@hidden>
  • Date: Fri, 28 Jan 2005 15:04:30 -0500
  • Organization: Rogue Research

Hi all,

So I'm still trying to get bindings support in my custom NSView subclass
working right... but I'm not understanding how a view should respond to
changes from the controller.

Consider mmalc's JoystickView.m and the method observeValueForKeyPath:
ofObject:change:context:.  My understanding is this: the model (or some
other view) informs the controller that the data at keyPath changed, the
controller informs the JoystickView (because the JoystickView registered
as an observer), and the JoystickView must then update its internal
state.  Firstly, is this right?

So, when "angle" changes, observeValueForKeyPath:... gets called and
JoystickView calls [self setValue:newAngle forKey:@"angle"], which
basically invokes setAngle:.  The stack at this point is:

#0	-[JoystickView setAngle:]
#1	-[NSObject(NSKeyValueCoding) setValue:forKey:]
#2	-[JoystickView observeValueForKeyPath:ofObject:change:context:]
#3	-[NSObject(NSKeyValueObservingPrivate) _notifyObserversForKeyPath:change:]
#4	-[NSController _notifyObserversForKeyPath:change:]
#5	-[NSController observeValueForKeyPath:ofObject:change:context:]
#6	-[NSArrayController observeValueForKeyPath:ofObject:change:context:]

Up to now, I *think* I understand everything.  *However*, if I comment
out the setValue:forKey: call, setAngle: is still called a little later!
 The stack is:

#0	-[JoystickView setAngle:] at JoystickView.m:492
#1	-[NSObject(NSKeyValueCoding) setValue:forKey:]
#2	-[NSObjectParameterBinder _updateObject:atIndex:observedController:
observedKeyPath:context:]
#3	-[NSObject(NSKeyValueObservingPrivate) _notifyObserversForKeyPath:change:]
#4	-[NSController _notifyObserversForKeyPath:change:]
#5	-[NSController observeValueForKeyPath:ofObject:change:context:]
#6	-[NSArrayController observeValueForKeyPath:ofObject:change:context:]

Why? And if it's going to be called 'magically' anyway, do I need call
it?  The reason I'm asking is because I found that things were working
'magically' without my view doing anything in observeValueForKeyPath:...

Thanks!

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada


 _______________________________________________
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

  • Prev by Date: Re: Debugging Bindings
  • Next by Date: Re: Retrieving the URL from a Safari copy
  • Previous by thread: Re: 2 NSDocuments with nib and info.plist problem - Solved
  • Next by thread: A case for overlapping views?
  • Index(es):
    • Date
    • Thread