RuLoViC
RuLoViC

Reputation: 855

Check if there are nspopover opened before creating new one

I have in my code some functionality to open a popover anytime an event happens. Problem is that if those events happen one after the other the popovers opened are overlapped.

I would like to close one popover when opening new one.

Is there any way to get from nswindow if there is an active popover?

Thanks in advance and regards

Upvotes: 0

Views: 585

Answers (2)

RuLoViC
RuLoViC

Reputation: 855

Finally I was able to figure it out by using notifications posted:

[[NSNotificationCenter defaultCenter]
    addObserver:self
       selector:@selector(popoverWillShow:)
           name:NSPopoverWillShowNotification
         object:nil];

And then in the selector I compare the objects: (popover is an NSPopover)

- (void)popoverWillShow:(NSNotification *)notification {
  if (![popover isEqual:[notification object]])
  [self close];
}

Upvotes: 1

vtukhtarov
vtukhtarov

Reputation: 1902

I think you need play with NSPopover's notification methods such as:

- (void)popoverDidShow:(NSNotification *)notification;
- (void)popoverWillClose:(NSNotification *)notification;

And add some logic which will hide not closed popover...

Upvotes: 1

Related Questions