Programmatically setting NSArrayController's contentArray
Programmatically setting NSArrayController's contentArray
- Subject: Programmatically setting NSArrayController's contentArray
- From: Dustin Voss <email@hidden>
- Date: Sat, 8 Nov 2003 23:35:33 -0800
I am trying to set an NSArrayController's "contentArray" key
programmatically, but I get an exception "Controller cannot be nil". I
don't know where to go from here. Am I doing something wrong?
My application has a main window with a sidebar-style table. The
sidebar should show a list of documents, provided by my document
manager.
I have a global instance of the document manager class in a variable
named "gDocManager". The document manager implements a "documents" key
returning an array of all the documents. It implements all the indexed
key-value coding forms. The documents themselves implement a "name" key
and represent channels.
The main window's NIB file owner is my window controller class. The NIB
has an NSArrayController called the channel list controller. The
channel list controller's "contentArray" binding is unbound in IB; I am
trying to bind it in the window controller's awakeFromNib method (this
fails). The channel list table (i.e. sidebar) has a column, where the
column's "value" binding is bound to the channel list controller's
"arrangedObjects" controller key and "name" model key path.
The window controller has an outlet called "theChannelListController"
which is connected to the NIB file's channel list controller (via the
File's Owner icon). Here is my awakeFromNib method:
- (void) awakeFromNib
{
[theChannelListController bind:@"contentArray" toObject:gDocManager
withKeyPath:@"documents" options:nil];
}
Here's what happens. When the user makes a new window, the app delegate
makes a new window controller, inits it with the main window's NIB
file, sets the new controller as the owner, and calls showWindow. This
eventually gets around to calling my window controller's awakeFromNib.
While executing bind:toObject:withKeyPath:options:, the system calls
[NSBinder
addBinding:toController:withKeyPath:valueTransformer:options:], which
throws the following exception:
Controller cannot be nil
I don't understand why this is happening. I have verified that
"theChannelListController" is an NSArrayController. IB shows that it
has a binding called "contentArray". I have verified that my
gDocManager object is valid, and that it has a method named
"documents", which is returning a valid, though empty, array.
Have I missed something?
BTW, I tried substituting [theChannelListController
setValue:gDocManager forKey:@"contentArray"] in my awakeFromNib method,
but the "contentArray" key isn't key-value-coding compliant according
to the exception I got.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.