FROM : Daniel Child
DATE : Mon Jan 21 05:57:14 2008
Ken,
Your explanation below was super helpful. I tried passing a reference
to the app controller directly as you suggest at the bottom, and that
worked.
Judging from the rest of what you wrote, I see that my next readings
should be on delegation and the responder chain. I will try those
approaches next. And as you mention, duplicate code was bothering me,
so I will try to put the window-opening code all in one place as well.
Thanks!
On Jan 20, 2008, at 5:45 AM, Ken Thomases wrote:
> The nib should not contain an instance of a NSWindowController-
> derived class. An NSWindowController is intended to be the owner
> of the nib. As such, it's outside of the nib -- "above" it, in a
> certain sense. So, when it comes time to load WindowC.nib, you do:
>
> WindowCController* myWindowCController = [[WindowCController
> alloc] initWithWindowNibName:@"WindowC"];
>
> In the nib, you would set the class of File's Owner to
> WindowCController. You'd also connect its "window" outlet to the
> window in the nib. Then, anywhere that some other part of the code
> needs to refer to WindowC, you use this expression:
>
> [myWindowCController window]
>
> If you want the WindowCController instance to know about the other
> windows, you can add some ivars to it and set them up. You can do
> that immediately after the alloc-init statement, above, or actually
> define your own custom init... method that takes additional arguments.
>
> One thing that might be confusing you: you might want a controller
> which manages the window controllers. Often, there's an
> application controller, which might also be the application
> delegate. This application controller is what knows about the
> various nibs and window controller classes. So, it is what would
> allocate and initialize the WindowCController instance, as
> illustrated above except that myWindowCController would not be a
> local variable, it would be an instance variable. The application
> controller would also have the "global" overview sufficient to
> connect the various nibs and window controllers to each other.
>
> How does a WindowCController get a pointer to the application
> controller? Well, it could be given one explicitly by the
> application controller when it creates the WindowCController
> instance. Or, the WindowCController can just use [NSApp delegate].
>
> -Ken
DATE : Mon Jan 21 05:57:14 2008
Ken,
Your explanation below was super helpful. I tried passing a reference
to the app controller directly as you suggest at the bottom, and that
worked.
Judging from the rest of what you wrote, I see that my next readings
should be on delegation and the responder chain. I will try those
approaches next. And as you mention, duplicate code was bothering me,
so I will try to put the window-opening code all in one place as well.
Thanks!
On Jan 20, 2008, at 5:45 AM, Ken Thomases wrote:
> The nib should not contain an instance of a NSWindowController-
> derived class. An NSWindowController is intended to be the owner
> of the nib. As such, it's outside of the nib -- "above" it, in a
> certain sense. So, when it comes time to load WindowC.nib, you do:
>
> WindowCController* myWindowCController = [[WindowCController
> alloc] initWithWindowNibName:@"WindowC"];
>
> In the nib, you would set the class of File's Owner to
> WindowCController. You'd also connect its "window" outlet to the
> window in the nib. Then, anywhere that some other part of the code
> needs to refer to WindowC, you use this expression:
>
> [myWindowCController window]
>
> If you want the WindowCController instance to know about the other
> windows, you can add some ivars to it and set them up. You can do
> that immediately after the alloc-init statement, above, or actually
> define your own custom init... method that takes additional arguments.
>
> One thing that might be confusing you: you might want a controller
> which manages the window controllers. Often, there's an
> application controller, which might also be the application
> delegate. This application controller is what knows about the
> various nibs and window controller classes. So, it is what would
> allocate and initialize the WindowCController instance, as
> illustrated above except that myWindowCController would not be a
> local variable, it would be an instance variable. The application
> controller would also have the "global" overview sufficient to
> connect the various nibs and window controllers to each other.
>
> How does a WindowCController get a pointer to the application
> controller? Well, it could be given one explicitly by the
> application controller when it creates the WindowCController
> instance. Or, the WindowCController can just use [NSApp delegate].
>
> -Ken
| Related mails | Author | Date |
|---|---|---|
| Daniel Child | Jan 13, 17:59 | |
| mmalc crawford | Jan 13, 19:35 | |
| mmalc crawford | Jan 13, 20:24 | |
| Daniel Child | Jan 18, 21:09 | |
| Ken Thomases | Jan 20, 11:45 | |
| mmalc crawford | Jan 20, 11:58 | |
| Ken Thomases | Jan 20, 14:21 | |
| Daniel Child | Jan 21, 05:57 |






Cocoa mail archive

