Skip navigation.
 
mlRe: Same NSObjectController, two nibs?
FROM : Christiaan Hofman
DATE : Fri Apr 01 20:26:56 2005

On Apr 1, 2005, at 21:15, Marc Respass wrote:

>
> On Apr 1, 2005, at 12:48 PM, Christiaan Hofman wrote:
>

>>
>> On Apr 1, 2005, at 20:27, Marc Respass wrote:
>>

>>> Hi All,
>>>
>>> I have two windows, Main and Login. Both use the same controller for
>>> user information, userController (an NSObjectController). I have one
>>> controller object, Controller.m, which is the main controller for
>>> the app and the owner of Login.nib. If I connect userController in
>>> MainMenu.nib and Login.nib, I get two different instances of
>>> userController so I only connect it in Login.nib and it only gets
>>> initialized when the Login panel goes up (which is fine since it's
>>> useless until a user logs in). The userController remains the same
>>> and it contains all the data I want but I am unable to display
>>> information from it in my main window (in MainMenu.nib). Any ideas
>>> about why or how to handle this?
>>>
>>> thanks a lot
>>> Marc
>>>

>>
>> This should work, in principle. But how do you connect, and when? In
>> the way you describe the userController is instantiated with
>> Login.nib, while you want to connect it to views in the Main.nib.
>> Both nibs should therefore have been loaded when you do the
>> programmatic binding.

>
> MainMenu.nib is loaded first, when applicationHasFinishedLoading,
> Login.nib is loaded. The userController is instantiated in Login.nib.
>

>> But why not just live with the 2 controllers?

>
> I was hoping it would work since the object that references
> userController is the same object. After the login panel is done,
> userController has been instantiated and filled with data. I can get
> data out of it but Cocoa bindings won't display data from it. It seems
> more a nib synchronization thing. Since userController is not
> connected to anything in MainMenu.nib, the main window isn't getting
> data from it? I guess I could make a loginController, then copy the
> data from that controller to userController once the login panel is
> dismissed. :::Shrug::: Considering all the time and energy Cocoa
> Bindings has saved me, this seems a small price to pay :)
>

I am a bit confused about that. You say the NSObjectController contains
the data? I am not sure if that is a good idea, also in view of MVC.

The way I thought about it (and would do it) is to have all the data in
Controller (I assume that is an NSObject subclass). Then putting a
NSObjectController (userController) in both the nibs, and bind anything
to that NSObjectController. After loading the nib you connect the
content of the NSObjectController to Controller (see link below), and
you are done. What is shared is Controller (the model object), and
there are 2 objectControllers for the 2 nibs.

>> BTW, if you are not aware of this, do not bind to the Nib file owner,
>> because of a retain loop bug.

>
> I wasn't aware. Thank you.
>
> Marc
>


See http://theobroma.treehouseideas.com/document.page/18

Christiaan

Related mailsAuthorDate
mlSame NSObjectController, two nibs? Marc Respass Apr 1, 19:27
mlRe: Same NSObjectController, two nibs? Christiaan Hofman Apr 1, 19:48
mlRe: Same NSObjectController, two nibs? Marc Respass Apr 1, 20:15
mlRe: Same NSObjectController, two nibs? Christiaan Hofman Apr 1, 20:26
mlRe: Same NSObjectController, two nibs? Marc Respass Apr 1, 23:17