Pregunta

I am a iOS developer and going to develop an OS X application. However they are so different from each other.

I want to add a splash screen at the application startup.

- (void) applicationDidFinishLaunching:(NSNotification *)aNotification {

 // Hide main window
 [self.window orderOut:nil];

 SplashWindowController *splashWindowController = [[SplashWindowController alloc] initWithWindowNibName:@"SplashWindowController"];

 [NSApp runModalForWindow:splashWindowController.window];
 [splashWindowController release];

 // Show main window
 ...

And here is "SplashWindowController.m"

- (void)windowDidLoad {
  [super windowDidLoad];

  [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(hideSplash) userInfo:nil repeats:NO];
}

- (void)hideSplash {
  [NSApp endSheet:self.window];
  [self.window orderOut:nil];
}

I can see the appeared splash, but hideSplash function is never called. What's the reason?

¿Fue útil?

Solución

I'm wondering that you don't get an error, but this line has a typo:

[NSTimer scheduledTimerWithTimeInterval:2.0 target self selector:@selector(hideSplash) userInfo:nil repeats:NO];

it should be

[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(hideSplash) userInfo:nil repeats:NO];

On the other hand, you could try this one:

NSTimer *theTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(hideSplash) userInfo:nil repeats:NO];
[[NSRunLoop mainRunLoop] addTimer:theTimer forMode:NSRunLoopCommonModes];

I'm not sure if the [NSTimer…] is destroyed too soon… Assigning it to an instance should be fine. Also afaik the run loop is interrupted so you could try adding the timer to the main run loop.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top