具体来说,它在文本字段焦点方面的行为不一致。
我有一个 LSUIElement 弹出状态菜单。在该菜单中有一个包含文本字段的视图。文本字段需要是可选择的——不一定是默认选择的,但无论如何。
单击状态项时,会触发
[NSApp activateIgnoringOtherApps:YES];
它工作,大约一半的时间。* 状态菜单的另一半似乎认为自己“在后台”,即使单击它也不会让我将注意力集中在文本字段上。(我知道状态项点击触发器正在触发 b/c 上面有一个 NSLog。)
这是 Apple 处理这些状态项的方式中的错误,还是我错误处理了 activateIgnoringOtherApps?
*事实上,它似乎只是在另一个应用程序激活后第一次失败。之后它工作正常。
完整的片段:
-(void)statusItemClicked:(id)sender {
//show the popup menu associated with the status item.
[statusItem popUpStatusItemMenu:statusMenu];
//activate *after* showing the popup menu to obtain focus for the text field.
[NSApp activateIgnoringOtherApps:YES];
}