2012-10-14 27 views
0

我是一名iOS開發人員,正在開發OS X應用程序。 然而,他們彼此如此不同。OSD [NSTimer scheduledTimerWithTimeInterval ...]函數在windowDidLoad中不起作用

我想在應用程序啓動時添加啓動畫面。

- (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 
... 

這裏是 「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]; 
} 

我可以看到出現了色斑,但hideSplash功能不會被調用。 是什麼原因?

回答

3

我想知道,你不會得到一個錯誤,但此行有一個錯字:

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

應該

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

在另一方面,你可以試試這個之一:

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

我不知道,如果[...的NSTimer]太快破壞......將其分配給一個實例應該罰款。另外afaik運行循環會中斷,因此您可以嘗試將計時器添加到主運行循環中。

+0

對不起,我打錯了。這不是正確的答案。我只是修改了這個問題。 – Yun

+0

我已經嘗試在SplashWindowController中添加NSTimer成員變量並保留...但結果是一樣的。 – Yun

+0

...你試過把它加入'mainRunLoop'嗎? ;-) – tamasgal

相關問題