Friday, November 19, 2010

Why Doesn't Repeating NSTimer Invalidate

Most likely your timer is started more than once. If you can't find why that happens (or is done by iOS for unknown reasons), easy and safe fix is to invalidate your timer just before you create it:
[self.myTimer invalidate];
self.myTimer = nil;
self.myTimer = [NSTimer scheduledTimerWithTimeInterval:1
    target:self
    selector:@selector(updateTime)
    userInfo:nil
    repeats:YES];
You can call [nil method] without problems in iOS.

No comments:

Post a Comment