我想打开第二个窗口,作为应用程序主窗口中某些字段的内容编辑器。我用自己的笔尖创建了一个自定义NSWindowController(称为ItemEditor)。
我用以下代码打开新窗口:
ItemEditor *editor = [[ItemEditor alloc] initWithWindowNibName:@"ItemEditor"];
[editor showWindow:nil];
[editor.window makeKeyAndOrderFront:nil];
新窗口会立即出现,然后立即消失。无论是initWithWindow:
和windowDidLoad
的itemEditor的是所谓的,但windowWillClose:
并非如此。
谁能告诉我这是怎么回事?我很困惑
发生的事情是您正在使用ARC ...,editor
在创建对象后,没有任何东西可以保留。这就是为什么它在创建后就消失了。
您需要在父窗口控制器中将“ editor
”设置为“ strong
”属性。
换句话说,在父视图控制器的.h文件中这样声明它:
@property (strong) ItemEditor *editor;
并使用以下代码替换上面的代码段的第一行:
self.editor = [[ItemEditor alloc] initWithWindowNibName:@"ItemEditor"];
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句