I am having a problem with Model window and NSTimer.
I am creating a window and running it as ModalForWindow. I am also creating NSTimer for some periodic purpose. When I am finished I stop the model in the NSTimer handler. However the control doesn't return the position where I have started the modalWindow. It only returns if I hover the mouse around the main application window or click somewhere.
When I try to debug it works fine.
Here is a sample code: In this code the NSLog (*NSLog(@"after [NSApp runModalForWindow:dialogWindow]")
is not hit unless I click somewhere in the application.
Any suggestions whether I am doing something wrong.
I am creating a window and running it as ModalForWindow. I am also creating NSTimer for some periodic purpose. When I am finished I stop the model in the NSTimer handler. However the control doesn't return the position where I have started the modalWindow. It only returns if I hover the mouse around the main application window or click somewhere.
When I try to debug it works fine.
Here is a sample code: In this code the NSLog (*NSLog(@"after [NSApp runModalForWindow:dialogWindow]")
Code:
// Here I start the ModalWindow
-(void) loadDialog
{
dialogWindow = [self window];
[[self window] setDelegate:self];* **
*[NSApp runModalForWindow:dialogWindow];
*NSLog(@"after [NSApp runModalForWindow:dialogWindow]");
** *
* [dialogWindow close];
* NSLog(@"after [dialogWindow close];");
}
// Here I create NSTimer and attach to currentRunLoop
- (void)windowDidBecomeMain:(NSNotification *)notification {* **
* * if (myTimer == nil) {
* * * * myTimer = [NSTimer scheduledTimerWithTimeInterval:0.25
* * * * * * * * * * * * * * * * * * * * * * * * target:self selector:@selector(statusTimerProc)
* * * * * * * * * * * * * * * * * * * * * * * userInfo:nil repeats:YES];
* * * * [[NSRunLoop currentRunLoop] addTimer:myTimer
* * * * * * * * * * * * * * * * * forMode:NSModalPanelRunLoopMode];
* * }
}
// NSTimer Handler where I stop Modal after some intervals
- (void)lcStatusTimerProc
{*
* * counter++;
* * if(counter == 20) {
* * * * [myTimer invalidate];
* * * * myTimer = nil;
** * * *
* * * * [NSApp stopModal];
* * }
* * else {
* * * * [label setStringValue:[NSString stringWithFormat:@"%u", counter]];
* * }* **
}
Last edited by a moderator: