[英]run timer automatically for first and second time
I am new to iPhone, What I want is that my timer call a function every second but for the very first time it must call the function at 2 second.我是 iPhone 新手,我想要的是我的计时器每秒调用一次 function,但这是第一次它必须在 2 秒时调用 function。
Any help will be really appreciated.任何帮助将不胜感激。 Thanks谢谢
take a variable取一个变量
BOOL isNotFirstTime;
And in the function that gets triggered after each 4 secs add the following code at the starting在每 4 秒后触发的 function 中,在开头添加以下代码
-(void)AfterOneSecondsFuction
{
if(!isNotFirstTime)
{
isNotFirstTime=YES;
return;
}
//YOUR CODE HERE...
}
This is how you give a call to the function这就是您致电 function 的方式
NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(AfterOneSecondsFuction) userInfo:nil repeats:YES];
First schedule a timer and have a BOOL
variable say isFirstTime
set as YES
;首先安排一个计时器并将一个BOOL
变量说isFirstTime
设置为YES
;
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(doSomething) userInfo:nil repeats:YES];
and in并且在
- (void)doSomething
{
if(isFirstTime)
{
isFirstTime = NO;
return;
}
// Do something
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.