Question

The question is pretty straightforward. I have a NSPopover property, that I use to present some information when the user clicks in a NSView of mine. Here's how I present the popover:

[self.boxPopover showRelativeToRect:NSMakeRect(0, 0, POPOVER_SIZE, POPOVER_SIZE) ofView:_clickedBox preferredEdge:NSMinYEdge];

The question is: is there a way to get the reference of the view used by the parameter ofView from the popover?

The user can click in a lot os this NSViews, that I keep track with this iVar. I'm doing a feature that would require to see if the new displayed view is different (or not) to the previous one.

I want something like:

if (self.boxPopover.viewDisplayed != _clickedBox) ...

Is there a way to get this reference from popover or it's really impossible?

Thanks in advance,

Était-ce utile?

La solution

If you look at your Xcode's AppKit/NSPopover.h, you'll see this in the NSPopover object:

NS_CLASS_AVAILABLE(10_7, NA)
@interface NSPopover : NSResponder {
@private
    ...
    ...
    id <NSPopoverDelegate> _delegate;
    ...
    ...
    NSView *_positioningView;
    ...
    ...

So the popover object keeps a pointer to its positioning view but also keeps it private, so it won't be available to subclasses.

One thing you could possibly do is write a category extension to NSPopover to add an API to return _positioningView.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top