开发者

NSTimer + Modal Problem

开发者 https://www.devze.com 2023-02-18 06:52 出处:网络
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'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.

0

精彩评论

暂无评论...
验证码 换一张
取 消