On Aug 8, 2009, at 13:35, Brian Carmalt wrote:
I am trying to figure out how to access a NSArrayController in one nib file from another nib. I have done the NSPersistentDocument tutorial and I am trying to apply what I have learned.
In general, it's not a great idea. It just makes the two nib files more tangled up than they need to be, for no real benefit. It seems better to have separate array controllers for different contexts, and to bind them to the same data model array if that's what they're supposed to show.
So in my MyDocument.nib there is a array controller I would like to bind to a NSComboBox from a NewObjectSheet.nib. I have a NewObjectSheetController in MyDocument.nib and the same controller is file's owner in the NewObjectSheet. The controller has an outlet which points to an array controller which I would like to bind to an NSComboBox in the NewObjectSheet.nib.
I don't think you mean what you say here. It sounds like you want to bind the combo box to the array controller, not the array controller to the combo box.
First I'm not sure if it is possible to bind the NSComboBox to the NewObjectSheetController's outlet to the array controller. Content would be bound to File's Owner with a model key path of self.arrayController Content Values would be bound to File's Owner with a model key path of self.arrayController.arrangedObjects Value be bound to File's Owner with a model key path of self.arrayController.selection.name
Well, all that *would* be fine, though incidentally you don't need "self." in any of the bindings. The only time you need to use "self" is when the model key path would otherwise be empty and you're required to put something there.
Also, you cannot bind anything to an outlet. You only bind to a property of an object. As it happens, in many cases, the KVC mechanism is happy to treat an instance variable (such as an outlet) as if it were a property of the same name, but it's not recommended to rely on this any more. Much better to define the properties you want in NewObjectSheetController, even if the properties just encapsulate the values of instance variables.
However, without knowing anything further about what you're trying to achieve, it would almost certainly be wrong to use this set of bindings. It looks like you're trying to use the combo box as a kind of "chooser" that picks one thing out of an array of things that the array controller supplies. IOW, you're expecting a combo box to be a kind of menu, but it's not -- it's a kind of text field. You should probably be using a NSPopUpButton instead, which *is* a kind of menu.
If the scenario above is not possible, what is the best way to set this up? Should I set up a new NSArrayController in the NewObjectSheet.nib, set its entity to the same entity in the array controller I would like to use and then use the NewObjectSheetController access to the Document's ManagedObjectContext(MOC) and bind the MOC of the array controller to the document MOC and then use the bindings in the normal way?
I'm not a big fan of putting window controllers (NewObjectSheetController) in a nib file. It means you unnecessarily create the window controller every time you open a document, whether or not you ever end up using the sheet. It also prevents you from communicating document-related state to the window controller's initialization, so you may end up inventing a means of communication between the document and the window controller that's more complicated than just having the document create the window controller when it needs it (and you end up preventing the window controller and all of its associated resources from being released when the sheet is closed).
_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com