0

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?

DownUnder
  • 23
  • 4
  • could you show the code that actually sets up the "`.popover`" property? – Michael Dautermann Aug 04 '13 at 05:34
  • It's a property on the CustomViewController and the relationship is setup in the NIB. `@property (assign) IBOutlet NSPopover *popover;`. My CustomViewController is the NIB's File's Owner class and is the contentViewController of the popover. – DownUnder Aug 04 '13 at 06:18

1 Answers1

0

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.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • tried adding in loadView before calling showRelativeToRect: but no difference. I also confirmed that the popover is not nil. – DownUnder Aug 05 '13 at 10:11