NSTimer +模态问题
我试图在将 NSWindow 作为模式运行时运行计时器,但不幸的是它根本不起作用。日志被调用,窗口出现并变成模态,但计时器从未被调用 - 为什么?我错过了什么吗?
NSLog(@"Checking...");
[[NSApplication sharedApplication] runModalForWindow:_Window];
_checkTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(check:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_checkTimer
forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] addTimer: _checkTimer
forMode:NSModalPanelRunLoopMode];
I'm trying to run a timer while running an NSWindow
as modal, but unfortunately it doesn't work at all. The log is called, the window appears and turns modal, but the timer is never called - why? Am I missing something?
NSLog(@"Checking...");
[[NSApplication sharedApplication] runModalForWindow:_Window];
_checkTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(check:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_checkTimer
forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] addTimer: _checkTimer
forMode:NSModalPanelRunLoopMode];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您出于某种原因需要在启动模态会话后添加计时器 - 那么只需将计时器添加到运行循环模式即可: NSModalPanelRunLoopMode
If you need for some reasons to add timer after starting modal session - so just add timer to run loop mode: NSModalPanelRunLoopMode
在开始模态会话之前尝试执行计时器/运行循环的操作。
Try doing your timer/runloop stuff before starting the modal session.