1

可能重复:
NSTimer 不会停止

如何停止/使 NSTimer 无效?

下面是代码:

- (void)autoscrollTimerFired:(NSTimer*)timer {

   NSLog(@"Each & Every Time this MEthods is called Even if I try to invalidate it in viewDidDisappear "); 
}


- (void)viewWillAppear:(BOOL)animated{

    if (autoscrollTimer == nil) {
        autoscrollTimer = [NSTimer scheduledTimerWithTimeInterval:(35.0/1000.0)
                                                           target:self
                                                         selector:@selector(autoscrollTimerFired:) 
                                                         userInfo:nil 
                                                          repeats:YES]; // To repeat this thread it's as per my requirement
    }
}

-(void) viewWillDisappear:(BOOL)animated {

    [autoscrollTimer invalidate];
}

所以,请建议我这样做......

4

1 回答 1

3

我有同样的问题。我猜你已经把它作为非原子属性,保留吗?

请这样做:

[self.autoscrollTimer invalidate];

谢谢。

于 2011-07-21T19:26:55.437 回答