macoscocoacocoa-touchnstouchbar

Knowing when NSPopoverTouchBarItem will show its collapsed view


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?


Solution

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