Skip navigation.
 
mlRe: Multiple windows from single nib-window object
FROM : Robert Sesek
DATE : Mon Aug 14 21:38:22 2006

On Aug 14, 2006, at 10:46, Trygve Inda wrote:

> I have a window in my nib that I would like to open multiple copies 
> of and
> then bind the elements to variables in an array. How can I open 3, 
> 4 or 5
> separate windows from a single Window "template" in my nib?


Create a (or modify your existing) class to be a subclass of 
NSWindowController. The change your constructor to look like this:

- (id)init
{
   if (self = [super initWithWindowNibName: @"YourWindowName"])
   {
       // do normal stuff that you'd normally do in init
   }
   return self;
}

Then in Interface Builder, drag this class in, and change the "File's 
Owner" custom class to your NSWindowController subclass. Set File's 
Owner's window outlet to be the window. Make sure you don't have any 
instances of the class instantiated in IB. All of your connections 
will now have to hook to File's Owner, not any instantiated version.

Finally, in the code that you want to bring up these many windows 
(for the sake of this message, I'll just say there's a NSButton with 
this action method connected to it), use this code:

- (IBAction)openNewWindow: (id)sender
{
   YourNSWindowControllerSubclass  *wc = 
[[YourNSWindowControllerSubclass alloc] init];
   [wc showWindow: self];
}

- Robert

Related mailsAuthorDate
mlMultiple windows from single nib-window object Trygve Inda Aug 14, 19:46
mlRe: Multiple windows from single nib-window object Robert Sesek Aug 14, 21:38
mlRe: Multiple windows from single nib-window object Matt Neuburg Aug 14, 22:37
mlRe: Multiple windows from single nib-window object Trygve Inda Aug 14, 23:59