开发者

NSWindow Modal Problems

开发者 https://www.devze.com 2023-02-24 09:38 出处:网络
I\'m running a modal window in my application, which works fine. The problem however seems to be dismissing the window.

I'm running a modal window in my application, which works fine. The problem however seems to be dismissing the window.

While the window closes, it takes at least 20 seconds for the application to continue (I show the modal window at startup), but it will continue instantly if I click on its dock icon.

Here's how I close the modal window:

[NSApp stopModal];
[updaterWindow orderOut:self];
[updaterWindow close]; 

I've tried various things to get the Application to continue faster, such as manually switching to the main run loop and speaking to the main window directly (asking it to become the key window), which all did not work. Same as before, 20 seconds wait or instant load when clicking on the dock icon.

What can cause something like this? I'm really baffled.

Edit:

My modal window is actually created in a really simple way. I run my window as modal:

[NSApp runModalForWindow:updaterWindow];

When I am done with things, I close it:

[NSApp stopModal];
[updat开发者_高级运维erWindow orderOut:self];
[updaterWindow close];

The window goes away, but it needs a click to the dock icon or anywhere on the screen for the app to continue.


I'm doing something similar in my app at the moment: I have an IBAction method that calls the modal window:

-(IBAction)showMyModalWindow:(id)sender {
    [theModalWindow makeKeyWindow];
    NSInteger retVal = [NSApp runModalForWindow:theModalWindow];
    [theModalWindow close];
    //continue and do somethin according the value in retVal
    [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
}

In this case theModalWindow is in it's own nib file has an NSObject in it that deals with the ok and cancel button to dismiss theWindow, by way of example here's the cancel button callback:

-(IBAction)cancelButton:(id)sender
{
    [NSApp stopModalWithCode:errAuthorizationCanceled];
}

The last line in showMyModalWindow: method seems to be what's needed in my case by sending the app forward... Hope that's of some use!

Todd.

0

精彩评论

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

关注公众号