Macos windowDidLoad中的OS X[NSTimer scheduledTimerWithTimeInterval…]函数不工作
我是一名iOS开发人员,打算开发一个OSX应用程序。 然而,它们之间却如此不同 我想在应用程序启动时添加一个启动屏幕Macos windowDidLoad中的OS X[NSTimer scheduledTimerWithTimeInterval…]函数不工作,macos,cocoa,splash-screen,nswindowcontroller,Macos,Cocoa,Splash Screen,Nswindowcontroller,我是一名iOS开发人员,打算开发一个OSX应用程序。 然而,它们之间却如此不同 我想在应用程序启动时添加一个启动屏幕 - (void) applicationDidFinishLaunching:(NSNotification *)aNotification { // Hide main window [self.window orderOut:nil]; SplashWindowController *splashWindowController = [[SplashWindowCo
- (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”
我可以看到出现的飞溅,但从未调用hideSplash函数。
原因是什么?我想知道您没有收到错误,但这行有一个输入错误:
[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…]是否被过早销毁…将其分配给实例应该可以。另外,如果运行循环被中断,您可以尝试将计时器添加到主运行循环中。我想知道您是否没有收到错误,但此行有一个输入错误:
[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…]是否被过早销毁…将其分配给实例应该可以。另外,如果运行循环被中断,您可以尝试将计时器添加到主运行循环中。对不起,我输入错误。这不是正确的答案。我刚刚修改了这个问题。我已经尝试在SplashWindowController中添加NSTimer成员变量并保留。。。但结果是一样的……您是否尝试将其添加到
mainRunLoop
?;-)scheduledTimerWithTimeInterval:invocation:repeats:和scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:创建自动添加到nsrunlop的计时器,这意味着您不必自己添加它们。将它们添加到nsrunlop是导致它们触发的原因。使用timerWithTimeInterval:invocation:repeats:和timerWithTimeInterval:target:selector:userInfo:repeats:,您必须手动将计时器添加到运行循环中。对不起,我输入错误。这不是正确的答案。我刚刚修改了这个问题。我已经尝试在SplashWindowController中添加NSTimer成员变量并保留。。。但结果是一样的……您是否尝试将其添加到mainRunLoop
?;-)scheduledTimerWithTimeInterval:invocation:repeats:和scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:创建自动添加到nsrunlop的计时器,这意味着您不必自己添加它们。将它们添加到nsrunlop是导致它们触发的原因。使用timerWithTimeInterval:invocation:repeats:和timerWithTimeInterval:target:selector:userInfo:repeats:,您必须手动将计时器添加到运行循环中