NSTextField isn't active on NSPopover attached to NSStatusItem

倖福魔咒の 提交于 2019-12-14 03:11:47

问题


I have a NSStatusItem created like this:

statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[statusItem setTitle:@"DS"];
[statusItem setHighlightMode:YES];
[statusItem setAction:@selector(StatusClicked:)];
[statusItem setTarget:self]; 

I also have a popover with customview. On the view I have textfield: http://d.pr/i/CWbr

My popover is shown like this:

- (void)StatusClicked:(id)sender {
    [self.popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMaxYEdge];
}

From a debuger I learned that sender here is an instance of NSStatusBarButton class.

The problem is that when the popover pops I can't type in textfield, it apears inactive: http://d.pr/i/q18U

The button is working though.

I think that problem is in the view I pass to ofView:. I tried to change it to a control on window like this:

 [self.popover showRelativeToRect:[sender bounds] ofView:self.postText preferredEdge:NSMaxYEdge];

And textfield became active (http://d.pr/i/DmTz) but I have no idea why this helps.

Why does my popover textfield becomes inactive when poped from menu? Why button works? How can I make textfield active?

P. S. My app is Application is agent (UIElement)


回答1:


After writing the question I thought this can be related to key windows. So I searched for this connection and found this question: Not being able to edit NSTextField on NSPopover even though Editable behavior is set

This answered my question perfectly. It apears to be a bug.



来源:https://stackoverflow.com/questions/15597665/nstextfield-isnt-active-on-nspopover-attached-to-nsstatusitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!