Re: Open a window created in another nib
Re: Open a window created in another nib
- Subject: Re: Open a window created in another nib
- From: mmalcolm crawford <email@hidden>
- Date: Wed, 28 Dec 2005 01:50:24 -0800
On Dec 28, 2005, at 1:13 AM, Andrea Salomoni wrote:
I created the nib using IB and choosing new application.
After it I made a new class and instatiated it in IB, connected an
outlet to the window.
I have another nib file (the main) with a button connected, I would
like to open the secondary nib file window clicking on it.
If I understand correctly what you've done, this is wrong. You don't
instantiate an instance of the window controller in a nib, it should
be the File's Owner -- you set the class of the File's Owner to be
your NSWindowController subclass. See <
http://developer.apple.com/
documentation/Cocoa/Conceptual/Documents/Concepts/
WinControllersAndNibs.html>.
I added in the controller.h this:
MYWindowController * theSecondWin;
in the .m file:
-(id)init
....
theSecondWin = [[MYWindowController]alloc]init];
....
}
You should initialise theSecondWin with initWithWindowNibName: -- see
<
http://developer.apple.com/documentation/Cocoa/Reference/
ApplicationKit/ObjC_classic/Classes/NSWindowController.html#//
apple_ref/occ/instm/NSWindowController/initWithWindowNibName:>
You typically display the window with showWindow: (see <http://
developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/
ObjC_classic/Classes/NSWindowController.html#//apple_ref/occ/instm/
NSWindowController/showWindow:>).
You should also consider giving variables more complete and accurate
names.
Finally, to return to the init method, you appear to have created an
infinite loop:
MYWindowController * theSecondWin;
in the .m file:
-(id)init
....
theSecondWin = [[MYWindowController]alloc]init];
....
}
When you create a new instance of MYWindowController, it will create
a new instance, which will in turn create another new instance etc.
I would recommend reading <
http://developer.apple.com/documentation/
Cocoa/Conceptual/AppArchitecture/index.html> and <http://
developer.apple.com/documentation/Cocoa/Conceptual/Documents/
index.html>.
mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden