Re: SplashScreen and RunLoop
Re: SplashScreen and RunLoop
- Subject: Re: SplashScreen and RunLoop
- From: Lorenzo <email@hidden>
- Date: Wed, 16 Jul 2003 01:41:43 +0200
Hi Dustin,
thank you. Yes, after I created the timers I called
[NSApp runModalForWindow:[splashWinCntrl window]];
So, cannot I create a modal dialog which closes after 3 seconds?
I presume there should be a way to do that.
Best Regards
--
Lorenzo
email: email@hidden
>
From: Dustin Voss <email@hidden>
>
Date: Tue, 15 Jul 2003 14:55:42 -0700
>
To: Lorenzo <email@hidden>
>
Cc: email@hidden
>
Subject: Re: SplashScreen and RunLoop
>
>
On Tuesday, July 15, 2003, at 12:39 PM, Lorenzo wrote:
>
>
> Hi,
>
> I am trying to make my splashScreen appear before an eventual Finder
>
> call to
>
> - (BOOL)application:(NSApplication *)theApplication
>
> openFile:(NSString *)filename
>
>
>
> So I decided to put the call openSplashScreen: within the method
>
> - (void)applicationWillFinishLaunching:(NSNotification *)notification
>
>
>
> It worked fine. Then I added a fine touch: a timer. So even if the user
>
> doesn't press a key to close the splashScreen window, my application
>
> fires
>
> the timer which closes the splashScreen window anyway after 3 seconds.
>
> So I wrote the following 3 methods:
>
>
>
>
>
> ////////////////////////////////////////////////
>
> -(void)openSplashScreen
>
> {
>
> if(splashWinCntrl == nil){
>
> splashWinCntrl = [[[SplashWinCntrl alloc]
>
> initWithWindowNibName:@"splash"] retain];
>
> }
>
>
>
> if(splashWinCntrl){
>
> timerSplash = [[NSTimer scheduledTimerWithTimeInterval:3
>
> target:self
>
> selector:@selector(stopModalWindow)
>
> userInfo:nil repeats:NO] retain];
>
>
>
> [[NSRunLoop currentRunLoop] addTimer:timerSplash
>
> forMode:NSModalPanelRunLoopMode];
>
>
>
> [[NSRunLoop currentRunLoop] addTimer:timerSplash
>
> forMode:NSEventTrackingRunLoopMode];
>
>
>
> [NSApp runModalForWindow:[splashWinCntrl window]];
>
> [self closeSplashScreen];
>
> }
>
> }
>
>
>
>
>
> ////////////////////////////////////////////////
>
> - (void)stopModalWindow
>
> {
>
> NSLog(@">>>>>>> stopModalWindow");
>
> [NSApp stopModal];
>
> }
>
>
>
>
>
> ////////////////////////////////////////////////
>
> -(void)closeSplashScreen
>
> {
>
> if(timerSplash){
>
> [timerSplash invalidate];
>
> [timerSplash release];
>
> timerSplash = nil;
>
> }
>
> if(splashWinCntrl){
>
> [[splashWinCntrl window] close];
>
> [splashWinCntrl release];
>
> splashWinCntrl = nil;
>
> }
>
> }
>
>
>
>
>
> Now, the timer fires, but it doesn't close the splashScreen window. I
>
> can
>
> see the log string @">>>>>>> stopModalWindow" but the splashScreen
>
> remains
>
> there until I click on the window. Why? Is the problem related to the
>
> NSRunLoop before the application did finish? More, if I put a NSButton
>
> on
>
> the splashScreen connected to the stopModalWindow: method, if I press
>
> that
>
> button, the window closes properly.
>
>
>
> So, why the timer doesn't run properly?
>
>
I bet the run-loop is in a modal mode. Try doing the splash-screen
>
after the app starts up.
>
The same thing happens when the delegate's applicationShouldTerminate
>
returns NSTerminateLater. It runs in a modal run-loop and timers don't
>
work, because they are usually created in the normal run-loop.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.