[英]is there timer in ios
I want to create a timer for example to count 2 sec and after each second an nslog type for example 1 sec passed我想创建一个计时器,例如计数 2 秒,然后每秒传递一个 nslog 类型,例如 1 秒
any suggestion to do that任何建议这样做
yes there is NSTimer, use it as -是的,有 NSTimer,将其用作 -
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector() userInfo:nil repeats:NO];
What you're after is NSTimer .你所追求的是NSTimer 。
Which, I can't not point out, even a cursory search of the framework docs would have turned up.其中,我不能不指出,即使是对框架文档的粗略搜索也会出现。 Laziness IS one of the three Virtues of the Programmer , but c'mon.
懒惰是程序员的三大美德之一,但来吧。
You can call your NSTimer like this你可以像这样调用你的 NSTimer
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(changeValue) userInfo:nil repeats:YES];
changeValue function can be like changeValue function 可以像
-(void)changeValue{
NSLog("calling function after every two seconds");
}
Yes, ios having timer which is used for periodically call method or button touchup event.是的,ios 具有定时器,用于定期调用方法或按钮触摸事件。 we can use it like following:
我们可以像下面这样使用它:
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(Your_target_Method)
userInfo:nil
repeats:NO];
NSInteger timer=0;
now call method every 1 sec现在每 1 秒调用一次方法
-(void)Your_target_Method{
timer=timer+1;
NSLog(@"Timer:%ld",timer);
}
Furthermore, visit https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Timers/Timers.html此外,请访问https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Timers/Timers.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.