2011-03-13 42 views

回答

0

我终于明白了。问题是我的基于文档的应用程序的每个窗口都是无边界的,最近我读到无边界窗口无法通过菜单项(或Cmd-W键)发送到firstResponder的performClose:方法关闭。所以我不得不来实现在窗口的子类的一些其他方法:

- (void)performClose:(id)sender { 
    [documentClass canCloseDocumentWithDelegate:self shouldCloseSelector:@selector(document:shouldClose:contextInfo:) contextInfo:NULL]; 
} 

- (void)document:(NSDocument*)doc shouldClose:(BOOL)shouldClose contextInfo:(void*)contextInfo { 
    if (shouldClose) 
     [doc close]; 
} 

- (BOOL)validateMenuItem:(NSMenuItem *)menuItem { 
    return ([menuItem action][email protected](performClose:))?YES:[super validateMenuItem:menuItem]; 
} 

- (BOOL)canBecomeMainWindow { 
    return YES; 
} 

- (BOOL)canBecomeKeyWindow { 
    return YES; 
} 

最后两个方法确保该窗口可以获取焦点以及其他一些功能可以执行(像textviews查找命令)。

0

Close菜单项没有将-performClose:方法发送到“First Responder”对象(最终成为NSWindow)?我在过去注意到,如果菜单项没有他们的行为目标,它们会显示为灰色。

相关问题