开发者

Open alert box (NASlert) with a delegate and block all other windows?

开发者 https://www.devze.com 2023-03-13 14:51 出处:网络
Is there a way to open a NSAlert window, set a delegate for didEnd callback and while the alert is shown, all other windows should be \"disabled\" (can the window itself but not pus开发者_运维技巧h an

Is there a way to open a NSAlert window, set a delegate for didEnd callback and while the alert is shown, all other windows should be "disabled" (can the window itself but not pus开发者_运维技巧h any button or change any text)?


In your NSAlert code add

NSModalSession session = [NSApp beginModalSessionForWindow:theWindow];
[NSApp runModalSession:session];
// NSAlert stuff here ...

In your didEnd callback add

[NSApp endModalSession:session];

For more information about modal windows read NSApplication's "Managing the Event Loop" section.

Update:

Here is a sample code from Apple's doc showing how to run modal without callbacks.

NSModalSession session = [NSApp beginModalSessionForWindow:theWindow];
for (;;) {
    if ([NSApp runModalSession:session] != NSRunContinuesResponse)
        break;
    [self doSomeWork];
}
[NSApp endModalSession:session];

0

精彩评论

暂无评论...
验证码 换一张
取 消