Question

I'm running an alert dialog as a sheet. The problem is, I only want to continue program execution when the sheet gets an answer. So I added default modal code from Apple :

NSModalSession session = [NSApp beginModalSessionForWindow:aWindow];
for (;;)
    if ([NSApp runModalSession:session] != NSRunContinuesResponse)
        break;
[NSApp endModalSession:session];

This made my code very clean, but there is one problem : if I do this, the sheet won't get in front of the menu bar anymore (I was using NSStatusWindowLevel to get that effect).

Has anyone a solution for this? I want to avoid did-end-selectors since they make code very messy. Thanks!

Was it helpful?

Solution

I had the same issue and found that I needed to set the window level in the session loop for it to work. In your case something like:

NSModalSession session = [NSApp beginModalSessionForWindow:aWindow];
for (;;) {
    [mySheet setLevel: NSStatusWindowLevel];
    if ([NSApp runModalSession:session] != NSRunContinuesResponse)
    break;
}
[NSApp endModalSession:session];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top