作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 iPhone TIMER 应用程序中,
经过一段时间后,我需要更改预定的方法......
-(void)startTimerAction
{
NSLog(@"Start timer Action");
NSLog(@"Time is Over %@",isTimeOver?@"YES":@"NO");
if(!isTimeOver)
{
timer_main = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(ShowActicity) userInfo:nil repeats:YES];
}
else if(isTimeOver)
{
timer_main = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(continueClock) userInfo:nil repeats:YES];
}
}
所以,为了停止并重新安排它,我正在这样做......以某种方式......
isTimeOver=YES;
[timer_main invalidate];
timer_main=nil;
[self startTimerAction];
为此,需要一些时间延迟或不需要的间隔才能在新方法中重新安排计时器....
怎样才能顺利完成......
我只是想用另一种方法重新安排计时器而不造成延迟......
现在我正在这样做来修复它......
NSTimeInterval x=[[timer_main fireDate] timeIntervalSinceNow];
[timer_main invalidate];
timer_main=nil;
sleep(x);
totalCount++;
seconds++;
if(seconds>59)
{
minutes++;
seconds=0;
}
[self startTimerAction];
谢谢...
最佳答案
您可以schedule repeating timers with a firedate :
NSTimer *timer = [[NSTimer alloc] initWithFireDate:fireDate
interval:interval
target:self
selector:@selector(foo)
userInfo:nil
repeats:YES];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:timer forMode:NSDefaultRunLoopMode];
关于iphone - NSTimer : How to change the scheduled method without having delay?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8834857/
我是一名优秀的程序员,十分优秀!