Mark Bridges
Mark Bridges

Reputation: 8458

NSAlert above NSPopover

I have an NSPopover which displays from an NSStatusItem. This Popover shows NSAlerts from time to time. The problem is these alerts always appear below the popover, even though they become the key window. Even if I drag it it's still below the popover. Is there a way of making the alerts above the popover?

Upvotes: 5

Views: 940

Answers (3)

Sentry.co
Sentry.co

Reputation: 5609

This will work: DispatchQueue.main.async { alert.window.level = .popUpMenu } // moves the alert above statusbar app

Upvotes: 1

Ryan H
Ryan H

Reputation: 1756

A workaround is to display the NSAlert using the method beginSheetModal instead of runModal. With beginSheetModal, you have to specify the window associated with the popover to attach the sheet to, and you'll need to use a completion handler. By attaching the sheet to the popover window, you can at least guarantee that the NSAlert will be displayed in front of the popover.

Changing the NSStatusWindowLevel of an NSAlert did not move the alert in front of a popover for me. This may have something to do with specific ways that NSAlerts are initialized.

Upvotes: 0

Taylor
Taylor

Reputation: 3231

NSStatusItems use window levels of NSStatusWindowLevel. So a popover or other child window shown from one will inherit that window level.

You should make sure that the Alert's window is at or above this window level.

Upvotes: 0

Related Questions