如何停止/使NSTimer无效

时间:2011-03-24 11:56:29

标签: ios4 timer ios-simulator nstimer iphone-sdk-4.1

  

可能重复:
  NSTimer doesn't stop

如何停止/使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];
}

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

1 个答案:

答案 0 :(得分:3)

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

请这样做:

[self.autoscrollTimer invalidate];

感谢。