iPhone - NSTimer not repeating after fire

前端 未结 8 1817
被撕碎了的回忆
被撕碎了的回忆 2021-02-19 16:14

I am creating and firing a NSTimer with:

ncTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                           target:sel         


        
8条回答
  •  面向向阳花
    2021-02-19 16:45

    You can't just assign to the timer that you have put as a property in your header. This should work:

    self.ncTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
    target:self selector:@selector(handleTimer:) userInfo:nil repeats: YES];

    Also: The fire method fires the timer, out of cycle. If the timer is non repeating it is invalidated. After the line that says fire, add this:

    
    BOOL timerState = [ncTimer isValid];
    NSLog(@"Timer Validity is: %@", timerState?@"YES":@"NO");
    

提交回复
热议问题