Re: Core data, NSArrayController and different nibs
Re: Core data, NSArrayController and different nibs
- Subject: Re: Core data, NSArrayController and different nibs
- From: Quincey Morris <email@hidden>
- Date: Thu, 6 Nov 2008 09:48:55 -0800
On Nov 5, 2008, at 23:50, Tomaž Kragelj wrote:
- MainMenu.nib: my AppController and all the NSArrayControllers with
bindings set properly so when an item is selected in the master
controller, it's details are handled by children controllers (all
data comes from managed context).
- MainWindow.nib: the main window with placeholder view (and the
rest of the common user interface).
- CustomView.nib: the actual views are implemented each in a
separate nib and are then moved as child view in the main windows
placeholder when necessary (similar to Apple's ViewController sample).
The problem I have is that the custom views need the data from the
array controllers defined in MainMenu.nib. It seemed logical to
create outlets to the array controllers in my AppController and
expose them through accessors to the rest of the controller layer.
In my custom views I would then bind the controls to these (like
Application.delegate.arrayController.arrangedObjects.key for
example). But this doesn't work - the bindings are ok, there's no
error, but I get no data.
So my next try was to add "proxy" array controllers inside the
custom view nibs and bind their content array to the file's owner
representedObject (which is set manually to the corresponding array
controller before the nib is loaded - like [viewController
setRepresentedObject:[[NSApp delegate] arrayController]]). This
works, but selection in master array controller is not propagated to
the custom view proxy child controller. Furthermore, if I release
the custom view and create it again, the contents are empty (it only
works the first time).
It seems to me that you have too many array controllers. If I
understand correctly ...
You should have a set of array controllers (master and detail) in each
of the view files. The master controller should have its content
binding set to your data model (the same place that your current
MainMenu.nib master array controller's content is bound to --
presumably Application.delegate.something). The detail controllers are
of course bound to the master controller in their own view file.
You don't need any array controllers in MainMenu.nib and should delete
them. In effect, you were trying to use the MainMenu.nib array
controllers as your data model, and that seems unnecessary, since you
know where to find your data model directly.
If you need to get to your array controllers programatically (e.g. if
you need to change the current selection), make outlets from your view
controllers to their array controllers. When you swap a view
controller into the window, you know which one it is, obviously, so
you can easily find the correct array controllers as
viewController.masterController etc. (If it's the window controller
doing the swapping, then it might be
windowController.viewController.masterController etc.)
HTH
_______________________________________________
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