来自NSStatusItem的NSPopover中未启用NSTextField

时间:2014-01-13 01:26:09

标签: macos nstextfield nspopover

这个问题已经回答Not being able to edit NSTextField on NSPopover even though Editable behavior is set,但是因为StackOverflow不允许你发表评论,除非你有一定的声誉,我不得不创建另一个线程。我完全按照答案解释没有运气。这是10.9与Xcode 5.我添加了NSWindow + CanBecomeKeyWindow.m到构建设置。因为这是一个只有状态栏的应用程序,我在应用程序中将应用程序代理设置为YES,并且我没有在应用程序中使用任何窗口。任何想法如何与小牛队实现这一点?

NSWindow+canBecomeKeyWindow.h
@interface NSWindow (canBecomeKeyWindow)

@end

NSWindow+canBecomeKeyWindow.m
@implementation NSWindow (canBecomeKeyWindow)

//This is to fix a bug with 10.7 where an NSPopover with a text field cannot be edited if its parent window won't become key
//The pragma statements disable the corresponding warning for overriding an already-implemented method
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
- (BOOL)canBecomeKeyWindow
{
    return YES;
}
#pragma clang diagnostic pop

@end

1 个答案:

答案 0 :(得分:0)

搞定了。您必须完全清除接口和实现代码,以便您只是覆盖NSWindow canBecomeKeyWindow方法。完全如上所列,并确保.m文件列在您的构建阶段。