解决方法
苹果在
Nib Loading上有一些有用的示例代码,但并不直接解决这个问题.以下代码.
@interface CloseWindowAppDelegate : NSObject <NSApplicationDelegate> { NSWindow *window; IBOutlet NSWindow * secondWindow; NSNib * secondNib; } @property (assign) IBOutlet NSWindow *window; - (IBAction)openSecondWindow:(id)sender; - (IBAction)closeSecondWindow:(id)sender; @end
#import "CloseWindowAppDelegate.h" @implementation CloseWindowAppDelegate @synthesize window; - (IBAction)openSecondWindow:(id)sender { secondNib = [[NSNib alloc] initWithNibNamed:@"SecondWindow" bundle:nil]; [secondNib instantiateNibWithOwner:self topLevelObjects:nil]; [secondWindow makeKeyAndOrderFront:nil]; } - (IBAction)closeSecondWindow:(id)sender { [secondWindow close]; [secondNib release]; } @end