I am running a custom NSWindowController as modal window.
First I show it like this:
ProgressWindow *pWin = [[ProgressWindow alloc] initWithWindowNibName:@"ProgressWindow" andXmlContent:nil];
[NSApp runModalForWindow:[pWin window]];
And then I want to dismiss it from within the ProgressWindow's NSWindowController. To do so I set at the windowDidLoad function following code (just to test):
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];
[self testMethod];
As expected, it calls testMethod after 2 Seconds The method should close the modal window, but I don't seem to find the way to do it. I have tried [NSApp stopModal]
, [NSApp abortModal]
, [self close]
, making it a sheet and calling [self.window orderOut:nil];[NSApp endSheet:self.window];
but nothing seems to work. Either nothing happens or the window reopens at another location. I do not know why this is happening, the initialization code is only called once.
Anyone knows how to close it???
I believe you are using the RunLoop in an incorrect manner. The RunLoop is a loop which manages display and interaction of the GUI widgets within your App, if you stop the main RunLoop your App will stop updating.
Since you are using runUntilDate, you are stopping the processing of the GUI updates since the main RunLoop has stopped.
To get the functionality you require you could use a addTimer to the runloop or use a separate NSTimer with the argument selector initiating the stopModal message.