在windowDidLoad中打开NSPopover [英] Open NSPopover in windowDidLoad

查看:88
本文介绍了在windowDidLoad中打开NSPopover的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打开窗口以向用户提供指令时在mac应用程序中显示NSPopover,但是不会显示弹出窗口.

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.

如果我通过按下按钮调用完全相同的函数,则弹出窗口会成功显示,但是当我在windowDidLoad中调用它时,不会显示.

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];

init方法只需调用以下内容,然后将自定义视图和控制器连接到NIB中.

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

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

有人碰到这个吗?

推荐答案

您正在以编程方式分配和初始化CustomViewController对象,但是在显示之前,弹出框没有机会从笔尖加载(在该行直接在alloc& init之后).

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];

在尝试显示"instruction.popover"时,您可能还想确保它也不为空.

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

这篇关于在windowDidLoad中打开NSPopover的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆