在我的主 ViewController 中,我有以下代码:
- (IBAction)listFunctions:(id)sender //button clicked
{
FunctionListController *functionListController = [[FunctionListController alloc] initWithWindowNibName:@"FunctionList"];
NSWindow *functionListWindow = [functionListController window];
[NSApp runModalForWindow: functionListWindow];
NSLog(@"done");
}
FunctionListController
是文件的所有者FunctionList.nib
和子类,NSWindowController
并实现了协议NSWindowDelegate
。
这里是实现FunctionListController
:
@implementation FunctionListController
- (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.
self.window.delegate = self;
}
- (void)windowWillClose:(NSNotification *)notification
{
[NSApp stopModal];
}
@end
当模态窗口关闭时,NSLog(@"done");
运行并显示,但是listFunctions
完成后,我得到一个 EXC_BAD_ACCESS 错误。
随着NSZombiesEnabled
我得到错误[NSWindow _restoreLevelAfterRunningModal]: message sent to deallocated instance
。
编辑:
我正在使用 ARC。