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
开发者_如何学C forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] addTimer: _checkTimer
forMode:NSModalPanelRunLoopMode];
If you need for some reasons to add timer after starting modal session - so just add timer to run loop mode: NSModalPanelRunLoopMode
[[NSRunLoop currentRunLoop] addTimer:theTimer
forMode:NSModalPanelRunLoopMode];
Try doing your timer/runloop stuff before starting the modal session.
精彩评论