How do I use a second window I created, is there a w开发者_JAVA技巧ay to open it when triggering an IBAction
event, e.g., a "touch down" event?
Usually, you create the window in a separate XIB file, and create a subclass of NSWindowController, that you set as the file owner of the XIB file.
Then, you need to override the init method to load the XIB file:
- ( id )init
{
if( ( self = [ super initWithWindowNibName: @"MySecondWindow" ] ) )
{}
return self;
}
Then, you just need to create a new instance of your second window controller, and show the window:
MyWindowController * wc = [ MyWindowController new ];
[ wc showWindow: nil ];
That can be done from your IBAction method.
Just to expand a tiny bit on what Macmade stated:
I prefer the formal allocating memory and initializing the object.
MyWindowController * wc = [[MyWindowController alloc] init];
[wc.window makeKeyAndOrderFront:self];
精彩评论