Re: NSObjectController, content outlet and content object question
Re: NSObjectController, content outlet and content object question
- Subject: Re: NSObjectController, content outlet and content object question
- From: Michael de Haan <email@hidden>
- Date: Wed, 1 Jul 2009 07:03:03 -0700
Hi Kevin,
thanks for answering.
Before I answer your specific enquiries....I was led to ask this by a
very similar question to the group:
"I have previously used the content outlet to establish a connection
between NSObjectController and its object. Is contentObject an
alternative way to do the same thing"
and the best reply by mmalc:
"If you set the contentObject of an object controller, then -- just as
anywhere else in Cocoa -- you're setting one of its properties
(typically an instance variable) and it's then the recipient's
responsibility to look after it.
............
If you bind the contentObject, they you're telling it to keep it
synchronised with whatever is at the end of the keypath you provided
from the source object."
So, when I emulated the currency converter, with bindings, I was
surprised when they connected the NSObjectController to the model
using the content outlet of NSObjectController, as per the above
discussion. ( What I **expected** (clearly incorrectly) was that, in
order for the project to work, one would have to bind the view to the
controller, then bind the controller to the model). So, I was puzzled
when **both** approaches worked ie binding the view to the controller,
and **either** binding the controller to the model ( with keypath
"self") OR setting the controller's content to the view. (Cntrl-
dragging from the controller to the model).
It might well be possible that I am thinking about the bindings
incorrectly...and in fact all one needs in this case is to bind the
view( textfield and slider) to the controller with the correct
keypath, and that the relationship of a controller to it's content is
the issue I am not completely understanding.
But..to your specific enquiries....
On Jun 30, 2009, at 9:42 AM, Kevin Cathey wrote:
Michael,
In IB, Bind the textField's and Slider's values to the model Key
Path "selection.number".
What are you binding to here? The object controller?
Yes...I am binding the value of either a slider or textField to the
NSObjectController with the model key path of
"selection.propertyOfTheModel" ( which happens to be number, a simple
float.
Connect the NSOjectController's outlet ( cntrl-drag to foo).
You have an outlet on "Foo" for the Object Controller?
NO...it's a simple Ivar ( float).
Another question, for the NSObjectController, do you have the check-
box "Prepares Content" turned on in the inspector?
..no...nothing is checked. The only thing I have filled in under keys
is the name of the ivar...though, I have removed this and it does not
seem to play a role in the successful running of the app.
Thanks Kevin.
Kevin
On 29 Jun 2009, at 15:23, Michael de Haan wrote:
May I indulge the group with an issue I have been trying to
understand for a few days. I have tried to read the extensive
literature and correspondence to the group, but so far have not
seen an answer that is specific to this question.
Given this simple app....which keeps a slider and textField's value
synchronized.
1) View consisting of a slider and a textField
2) Model (Foo) with a single property "number"
3) NSObjectController
I am able to use 2 configurations to get the app to work.
Config (1).
In IB, Bind the textField's and Slider's values to the model Key
Path "selection.number".
Connect the NSOjectController's outlet ( cntrl-drag to foo).
Config (2)
As config (1) ...first line only.... now Bind NSObjectController
to Foo, with the model Key Path = self.
Could someone please explain why both work, and any reason for
choosing one over the other.
Thanks in advance.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden