我有一个奇怪的计时器问题。计时器在应用程序中更新良好。我正在展示代码。
//开始计时
#pragma mark- Timer
- (void)startTimer
{
timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateTimer:) userInfo:nil repeats:YES];
}
//更新定时器
- (void)updateTimer:(NSTimer *)theTimer
{
NSLog(@"called");
}
问题: 当我在 textview updateTimer 方法停止调用,当我停止时 滚动然后开始更新计时器。
现在如何继续调用更新定时器方法?
最佳答案
要解决此问题,您需要将 NSTimer 添加到 mainRunLoop 中。比如,
- (void)startTimer
{
timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateTimer:) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}
关于ios - scheduledTimerWithTimeInterval 在滚动时不更新计时器方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23926073/