我在这里做错什么了?我遗漏了什么?
- (void)scheduleTimer
{
NSTimer *timer = [NSTimer timerWithTimeInterval:0.15
target:self
selector:@selector(wtf:)
userInfo:nil
repeats:NO];
// This works fine
// [[NSRunLoop currentRunLoop] addTimer:timer
// forMode:NSDefaultRunLoopMode];
// This doesn't work at all - how come?
[[NSRunLoop currentRunLoop] addTimer:timer
forMode:@"MyCustomRunLoopMode"];
}
- (void)wtf:(NSTimer *)aTimer
{
NSLog(@"wtf");
}NSRunLoop的文档似乎表明可以创建自定义运行环模式。我是不是遗漏了什么?
(这是在Mac中标准GUI应用程序的主线程上)
更新:注意,我提到这是在标准应用程序的主线程上提到的。因此,我并不是亲自运行运行循环。这一切都是由NSApplication处理的。
发布于 2009-02-26 21:24:36
您是否正在运行该模式的运行循环?如果运行循环从未在该模式下运行,只添加一个计时器就不会做任何事情。
发布于 2009-02-26 21:26:51
难道currentRunLoop只在公共模式下运行吗?
您还应该尝试:- (BOOL)runMode:(NSString *)模式beforeDate:(NSDate *)limitDate
并使用:- (NSString *)currentMode进行检查
--汤姆
https://stackoverflow.com/questions/592474
复制相似问题