self.timerProgress=[NSTimer scheduledTimerWithTimeInterval:50.0 target:self selector:@selector(stopProgressView) userInfo:nil repeats:NO];
-(void)stopProgressView
{
if ([self.timerProgress isValid]) {
[self.timerProgress invalidate];
self.timerProgress=nil;
}
}
当我试图使 NSTimer 对象无效时单击按钮
-(void)cancelTimer
{
if ([self.timerProgress isValid]) {
[self.timerProgress invalidate];
self.timerProgress=nil;
}
}
它不会失效。它在间隔 50 后调用一次 stopProgressView。 如何解决这个问题?
最佳答案
- (IBAction)stopTimer {
if ([timerProgress isValid]) {
[timerProgress invalidate];
}
}
不要使用 self.timerProgress
只使用 timerProgress
关于ios - 如何使 NSTimer 失效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15217156/