简体   繁体   中英

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.

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

-(void)AfterOneSecondsFuction
 {
   if(!isNotFirstTime)
   {
    isNotFirstTime=YES;
    return;
   }
  //YOUR CODE HERE...
 }

This is how you give a call to the 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 ;

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(doSomething) userInfo:nil repeats:YES];

and in

- (void)doSomething
{
if(isFirstTime)
{
isFirstTime = NO;
return;
}
// Do something


}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM