M
//
// form2.m
// test_multi_window
//
// Created by on 23/7/14.
// Copyright (c) 2014 EDU. All rights reserved.
//
#import "form2.h"
@interface form2 ()
@end
@implementation form2
- (id)init
{
if (![super initWithWindowNibName:@"form2"])
{
return nil;
}
return self;
}
- (id)initWithWindow:(NSWindow *)window
{
self = [super initWithWindow:window];
if (self) {
// Initialization code here.
}
return self;
}
- (void)windowDidLoad
{
[super windowDidLoad];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}
- (IBAction)showWindow:(id)sender
{
[[NSApplication sharedApplication] runModalForWindow:self.window];
}
-(void)closeModalWindow:(id)sender
{
[[NSApplication sharedApplication] stopModal];
}
- (void)windowWillClose:(NSNotification *)notification
{
[self performSelectorOnMainThread:@selector(closeModalWindow:) withObject:nil waitUntilDone:NO];
}
- (IBAction)OnBT_OK:(id)sender
{
[self close];
}
@end
H
//
// form2.h
// test_multi_window
//
// Created by on 23/7/14.
// Copyright (c) 2014 EDU. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface form2 : NSWindowController
@end
调用
@property (assign) form2 *m_form2;
在m文件要引用1下
或者
@property (retain) form2 *m_form2;
在m文件要引用1下
或者
@interface EDUAppDelegate : NSObject <NSApplicationDelegate>
{
form2 *m_form2;
}
- (IBAction)OnBT_Form2_Show:(id)sender
{
if (m_form2 == nil)
{
m_form2 = [form2 new];
[m_form2 showWindow:self];
}
else
{
[m_form2 showWindow:self];
}
}