Cocoa NSWindowController';窗户立即打开
我正在尝试使用我的应用程序代理中的NSWindowController打开窗口。 我创建了一个带有相关NIB的基本NSWindowController,并尝试以这种方式显示窗口:Cocoa NSWindowController';窗户立即打开,cocoa,osx-lion,automatic-ref-counting,nswindowcontroller,Cocoa,Osx Lion,Automatic Ref Counting,Nswindowcontroller,我正在尝试使用我的应用程序代理中的NSWindowController打开窗口。 我创建了一个带有相关NIB的基本NSWindowController,并尝试以这种方式显示窗口: @implementation MyAppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // Show the main window from a separate nib MyWind
@implementation MyAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Show the main window from a separate nib
MyWindowController * theWindowController = [[MyWindowController alloc] initWithWindowNibName:@"MyWindowController"];
[theWindowController showWindow:self];
}
@end
当我启动应用程序时,MyWindowController的窗口只出现了几分之一秒(似乎一启动就被释放)
使用ARC,我怎么能强迫窗户粘住而不立即被冲洗?我不使用NSDocuments,我希望能够同时使用其中许多MyWindowController。您需要将保留WindowController的属性添加到您的应用程序委托(或在应用程序的生命周期内一直存在的其他对象)。例如:
@interface MyAppDelegate : NSObject
@property (strong, nonatomic) MyWindowController * windowController;
@end
然后在初始化窗口控制器时设置此属性
@implementation MyAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Show the main window from a separate nib
self.windowController = [[MyWindowController alloc] initWithWindowNibName:@"MyWindowController"];
[theWindowController showWindow:self];
}
@end
如果我想用windowController打开相同的窗口怎么办?当我呼叫第二个时,第一个立即释放。如果我创建windowController1,它会工作,但我想创建更多。@mohacs您需要保存显示的每个窗口控制器。也为第二个属性创建新属性。需要创造更多吗?创建
NSMutableArray
并将它们添加到那里。