iPhone - NSTimer not repeating after fire

前端 未结 8 1812
被撕碎了的回忆
被撕碎了的回忆 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:51

    The -fire: method manually fires it once. For a timer to be started and repeat, you have to add it to a runloop using [[NSRunLoop currentRunLoop] addTimer: forMode:]

    0 讨论(0)
  • 2021-02-19 16:56

    Assigning to ncTimer as you have will not initiate the properties retain functionality.

    Assuming the declaration is within the member object you will need to do:

    self.ncTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(handleTimer:) userInfo:nil repeats:YES]
    
    0 讨论(0)
提交回复
热议问题