Re: Manual binding questions.
Re: Manual binding questions.
- Subject: Re: Manual binding questions.
- From: Jiva DeVoe <email@hidden>
- Date: Sun, 23 Jan 2005 20:59:58 -0700
I think I'm beginning to see now... Your comments about models and
controllers being observable, and view and controllers being observers.
Of course, an NSSlider is a view... that makes sense.
So it seems like in order to handle those notifications, I have to
implement observeValueForKeyPath:ofObject:change:context: right? (Of
course, that makes sense now) but... it also appears, unless I am
mistaken, in order to get those notifications, I have to call
addObserver:forKeyPath:options:context ? If so... then what purpose
does bind:toObject:withKeyPath:options: serve?
This text from that doc tends to indicate the observation is set up for
me with this function:
" From the perspective of model-initiated updates the method can be
interpreted as follows:
toObject: GraphicController
If the GraphicController’s
withKeyPath:@"selection.shadowAngle"
selection.shadowAngle changes
bind:@"angle"
update whatever is associated with the exposed angle key
options:options
using the options specified (for example, using a value transformer).
The receiver therefore registered as an observer of the specified
object’s key path (selection.shadowAngle) in its
bind:toObject:withKeyPath:options: method, as was shown in Listing 2.
Observed objects notify their observers by sending them an
observeValueForKeyPath:ofObject:change:context: message. Listing 4
shows a partial implementation for the Joystick class for handling the
observer notifications that result."
If so - then what purpose does the addObserver:forKeyPath.... function
serve?
Sorry for all the questions... been wrestling with this all weekend and
trying to get it fully.
On Jan 23, 2005, at 7:50 PM, mmalcolm crawford wrote:
On Jan 23, 2005, at 6:09 PM, Jiva DeVoe wrote:
Ok, so slider not posting KVO change notifications explains that. I
have read through the linked doc a bunch of times (that's the only
doc on bindings I can find really)
That document is one of a collection:
<http://developer.apple.com/documentation/Cocoa/Conceptual/
CocoaBindings/index.html>
But I don't see a list there of what DOES post change notifications
and what doesn't. How does one know? And what's the recommended way
to handle a control like that then?
From
<http://developer.apple.com/documentation/Cocoa/Conceptual/
CocoaBindings/Concepts/WhatAreBindings.html> and
<http://developer.apple.com/documentation/Cocoa/Conceptual/
CocoaBindings/Concepts/HowDoBindingsWork.html>
(sections on Key-Value Observing):
Models and controllers post KVO notifications, controllers and views
observe.
Ie: In another case, I have an array of arrays managed through an
NSArrayController. So, I have a view that I want to bind the
currently selected array to so that I can do something with that
array. However, my NSArrayController only seems to post change
notifications when I click outside the tableview handling the current
selection and not when I click around in the tableview on different
elements of the array.. Why is this?
Example of what I mean:
MyDocument.h:
IBOutlet NSArrayController mailboxesController;
MailboxView *mailBox;
MyDocument.m:
-(void)awakeFromNib;
{
[mailBox bind:@"mailArray" toObject:mailboxesController
withKeyPath:@"selection.mail" options:nil];
}
In IB, I have a NSTableView view bound to my mailboxesController
which shows my array of mailboxes. As I click the different
mailboxes, my "mailArray" setter in MailboxView does *not* get
called. But if I click outside the nstableview, it does.
A quick answer for now: does MailboxView implement a custom
observeValueForKeyPath:ofObject:change:context: method? How is it
responding to KVO change notifications? See
<http://developer.apple.com/documentation/Cocoa/Conceptual/
KeyValueObserving/index.html> for a conceptual overview, and "Graphics
Bindings" at
<http://homepage.mac.com/mmalc/CocoaExamples/controllers.html> for a
worked example of implementing a custom bindings-enabled view.
mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
--
Jiva DeVoe
jiva at devoesquared.com
http://www.devoesquared.com
_______________________________________________
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