Binding to a controller in a different nib
-
Please help me extend my understanding of bindings...I grasp the
simple stuff, but not yet to an extent to be able to apply that to
complex situations.
In my main window (which resides in it's own nib, and is controlled by
a custom window controller), I have a combobox. I'd like to populate
the contents of that via bindings.
In my main nib file is where the controller lives that maintains the
information that I want to populate that combobox with. This
controller has a dictionary ("infoDictionary"), and the keys of that
dictionary are what I want displayed in the combobox.
My main window class has a member variable (I'm calling this
"infoController") that is a link to that information controller. So,
I attempted to set up the binding on the combobox as:
Bind to: File's Owner (which is my custom window controller)
Model Key Path: infoController.infoDictionary.allKeys
Truth be told, I didn't really expect that work (and I wasn't
disappointed), but I'm really clueless as to what *should* work.
As another stab in the dark, when I set the contents of that
dictionary, I tried wrapping that code around calls to:
[self willChangeValueForKey:@"infoController.infoDictionary.allKeys"];
<populate the dictionary here>
[self didChangeValueForKey:@"infoController.infoDictionary.allKeys"];
and that likewise didn't work; the combobox remains empty. (I also
tried throwing a "self." at the beginning of the Model Key Path to no
avail.)
I also get no output in my debugger console that might lead me to a
clue as to what I'm doing wrong.
Help, please? Thanks!
randy -
Responding to my own post, for clarification...
On Feb 28, 2008, at 10:47 AM, Randall Meadows wrote:> In my main window (which resides in it's own nib, and is controlled
> by a custom window controller), I have a combobox. I'd like to
> populate the contents of that via bindings.
>
> In my main nib file is where the controller lives that maintains the
> information that I want to populate that combobox with. This
> controller has a dictionary ("infoDictionary"), and the keys of that
> dictionary are what I want displayed in the combobox.
>
> My main window class has a member variable (I'm calling this
> "infoController") that is a link to that information controller.
> So, I attempted to set up the binding on the combobox as:
Ok, so I created an NSArrayController object in my window's nib file,
connected that to an outlet in my window class. In awakeFromNib: I
grab the keys from the infoController's infoDictionary, and pass that
to the array controller via addObjects:. It successfully populates my
combobox's content (now I just gotta work on selecting the right one).
Is this the correct way to do this? To me, it seems like a long-
winded route to get there, but then, I think that a LOT about
bindings. Is this just due to my inexperience with bindings? Or do I
just need to keep drinking the kool-aid until it eventually clicks?
(Or, are bindings *really* that roundabout?)
Thanks!
randy -
On Thu, Feb 28, 2008 at 12:47 PM, Randall Meadows <cocoa-dev...> wrote:> Please help me extend my understanding of bindings...I grasp the
> simple stuff, but not yet to an extent to be able to apply that to
> complex situations.
>
> In my main window (which resides in it's own nib, and is controlled by
> a custom window controller), I have a combobox. I'd like to populate
> the contents of that via bindings.
>
> In my main nib file is where the controller lives that maintains the
> information that I want to populate that combobox with. This
> controller has a dictionary ("infoDictionary"), and the keys of that
> dictionary are what I want displayed in the combobox.
Wire up the controller to an infoController outlet in your application
delegate, then bind the combo box to
NSApplication.delegate.infoController with whatever keypath you'd
like.
--Kyle Sluder


