|Jun 15, 2009, 04:20 AM||#1|
Close NSAlert after some time using Timer
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
[[NSRunLoop currentRunLoop] addTimer:myTimer forMode:NSModalPanelRunLoopMode];
int choice = 0;
choice = [alert runModal];
if(choice != 0)
-(void) killWindowNSTimer *) theTimer
[[alert window] close];
Can anyone please suggest the best way to do this.
|Jun 15, 2009, 11:22 AM||#2|
Why do say you know it's wrong? You said it works, right? Only thing I can see is you set of for 5 seconds when you said you wanted 10.
Go outside, the graphics are amazing!
|Jun 16, 2009, 01:19 AM||#3|
Yeah, if it's working for you then I wouldn't bother changing it. Despite that, that's how I'd do it; an NSTimer controlling NSAlert.
Sometimes you have to just let code be code
13" MacBook Pro - 2.53 GHz C2D - 500GB HDD - 8GB RAM
- Samsung Galaxy Nexus LTE
|Mar 22, 2013, 12:27 PM||#4|
I used this same code, but when I try to close with a timer, the rest of my app freezes. Also, if I try to do NSApp.stopModal to stop running Modal, the app crashes. Any ideas on the correct way to do this?
|Mar 22, 2013, 02:23 PM||#5|
I'd try abortModal instead of stopModal, that's what the documentation says. And your memory management seems dubious. [autorelease] should release the alert before the next round of the run loop, so by the time the timer fires, the alert should be gone. What does the static analyzer think of your code?
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|ultrasn0wed iPhone 4 signal goes after some time||widoq5||iPhone Tips, Help and Troubleshooting||1||Jan 7, 2011 07:25 AM|
|RDesktop: Becoming slow after some time||dev-random||Mac OS X Server, Xserve, and Networking||4||Oct 9, 2010 11:17 AM|
|MBP screen begins to stutter after some time||de.user||MacBook Pro||0||Jul 19, 2010 04:33 PM|
|Wallpaper changes to the default one after some time...!||tatineni||Mac OS X||9||Nov 9, 2009 10:48 AM|
|EyeTV Sleep Timer? Stop Programs after some time?||fleshman03||Mac Applications and Mac App Store||3||Jan 29, 2009 12:13 PM|
All times are GMT -5. The time now is 02:53 AM.