NSTimer does not shoot

In life, I cannot understand why this NSTimer will not shoot. here is all the code that seems relevant (at least for me)

- (IBAction)connectClick:(id)sender
{
    if (connected)
    {
        NSLog(@"Disconnecting");
        [timer invalidate];
        timer = nil;
        connected = NO;
        [Connect setStringValue:@"Connect"];
        NSLog(@"Finished\n");
    }
    else
    {
        NSLog(@"Connecting");
        timer = [NSTimer timerWithTimeInterval:2.0 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];
        //[timer fire]; tested this line. same results
        [Connect setStringValue:@"a"]; 
        connected = YES;
        NSLog(@"Finished\n");
    }
}

- (void)timerFireMethod:(NSTimer*)theTimer
{
    NSLog(@"Fireing event");
    //[self resetRequest];
    //[spinner startAnimation:nil];
    //[request startAsynchronous];
}

I read apple docs and other questions, but I can't figure it out. He doesn't even call timerDireMethod:once. I heard that this can be caused by different threads, but as far as I can tell, I do not use multiple threads.

Any ideas are welcome.

+5
source share
2 answers

From NSTimer Documentation for Mac OS X:

, addTimer: forMode:. , , , message aSelector to target. ( , .)

+[NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:]

, , , NSTimer , . , , .

+9

, + timerWithTimeInterval: target: selector: userInfo: repeat::

, addTimer: forMode:. , , , message aSelector to target.

+1

All Articles