gpt4 book ai didi

objective-c - 关闭模态窗口时的 EXC_BAD_ACCESS ([NSWindow _restoreLevelAfterRunningModal] : message sent to deallocated instance)

转载 作者:行者123 更新时间:2023-12-02 05:32:13 41 4
gpt4 key购买 nike

在我的主 ViewController 中,我有以下代码:

- (IBAction)listFunctions:(id)sender //button clicked
{
FunctionListController *functionListController = [[FunctionListController alloc] initWithWindowNibName:@"FunctionList"];

NSWindow *functionListWindow = [functionListController window];

[NSApp runModalForWindow: functionListWindow];

NSLog(@"done");
}

FunctionListControllerFunctionList.nib 的文件所有者和 NSWindowController 的子类,并实现协议(protocol) 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。

最佳答案

尝试 [functionListWindow setReleasedWhenClosed:NO] 并保持对窗口的强引用直到关闭。

关于objective-c - 关闭模态窗口时的 EXC_BAD_ACCESS ([NSWindow _restoreLevelAfterRunningModal] : message sent to deallocated instance),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12216637/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com