Knowing when NSPopoverTouchBarItem will show its collapsed view

66 Views Asked by At

I have an NSPopoverTouchBarItem in my Touch Bar, created in Interface Builder.

The popover has a custom NSView inside it, and want to load data in it only when the view is activated, but I can't find any way to recognize when the contained NSTouchBar or NSView becomes visible.

According to docs, NSTouchBarDelegate does not have any delegate methods for the view appearing, either.

enter image description here

Which class should I subclass, or should I be monitoring viewWillDraw on my custom NSView and set up some hacky scheme?

1

There are 1 best solutions below

0
Tritonal On BEST ANSWER

The docs were not too clear, but subclassing NSPopoverTouchBarItem gives you -(void)showPopover:(id)sender and -(void)dismissPopover:(id)sender.

You can then define a delegate method to tell the parent class that this popover did show.

-(void)showPopover:(id)sender {
    [super showPopover:sender];
    [self.delegate touchPopoverDidShow];
}