Hi,
I want to close a alert Window (NSAlert) after specific period of time if user
does not click on any of the buttons.
Is there a way to set up a NSTimer to close the Alert Panel after 10 secs.
I am doing following thing and its working. But I know this wrong way to do this.
..........................................
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert addButtonWithTitle: @"OK"];
[alert setMessageText: @"Attention!!! This a critical Alert."];
[alert setAlertStyle: NSInformationalAlertStyle];
NSTimer *myTimer = [NSTimer timerWithTimeInterval: 5
target:self
selector: @selector(killWindow
userInfo:nil
repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:myTimer forMode:NSModalPanelRunLoopMode];
int choice = 0;
choice = [alert runModal];
if(choice != 0)
[myTimer invalidate];
..........................................
-(void) killWindowNSTimer *) theTimer
{
NSLog(@"killWindow");
[[alert window] close];
}
..........................................
Can anyone please suggest the best way to do this.
Thanks,
Tejashree.
I want to close a alert Window (NSAlert) after specific period of time if user
does not click on any of the buttons.
Is there a way to set up a NSTimer to close the Alert Panel after 10 secs.
I am doing following thing and its working. But I know this wrong way to do this.
..........................................
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert addButtonWithTitle: @"OK"];
[alert setMessageText: @"Attention!!! This a critical Alert."];
[alert setAlertStyle: NSInformationalAlertStyle];
NSTimer *myTimer = [NSTimer timerWithTimeInterval: 5
target:self
selector: @selector(killWindow
userInfo:nil
repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:myTimer forMode:NSModalPanelRunLoopMode];
int choice = 0;
choice = [alert runModal];
if(choice != 0)
[myTimer invalidate];
..........................................
-(void) killWindowNSTimer *) theTimer
{
NSLog(@"killWindow");
[[alert window] close];
}
..........................................
Can anyone please suggest the best way to do this.
Thanks,
Tejashree.