Open NSPopover in windowDidLoad

不羁岁月 提交于 2019-12-13 03:36:59

问题


I am trying to display an NSPopover in a mac application when the window opens to give the user an instruction, but the popover will not display.

If I call the exact same function from a button press then the popover successfully displays, but when I call it in windowDidLoad it doesn't.

I can see that the control I am presenting it from has a bounds, so I don't think that is the problem. I've also checked that the behaviour of the popover is not transient, so it shouldn't close without intervention.

In my function I'm passing some variables into a custom initialiser, but it is basically just this:

CustomViewController *instruction = [[CustomViewController alloc] init];
[instruction.popover showRelativeToRect:[aField bounds] ofView:aField preferredEdge:NSMaxXEdge];

The init method simply calls the following, and the custom view and controller are hooked up in the NIB.

[super initWithNibName:@"InstructionalView" bundle:nil]

Has anyone come accross this?


回答1:


You're programmatically allocating and init-ing your CustomViewController object, but the popover doesn't have a chance to load from the nib before you display it (on the line directly after the alloc & init).

Between those two lines, force a load via loadView, like this:

[instruction loadView];

You may also want to make certain that "instruction.popover" isn't nil when you try to display it, too.



来源:https://stackoverflow.com/questions/18039909/open-nspopover-in-windowdidload

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