Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone定时器-如何等待秒数?_Iphone_Timer_Nstimer - Fatal编程技术网

iPhone定时器-如何等待秒数?

iPhone定时器-如何等待秒数?,iphone,timer,nstimer,Iphone,Timer,Nstimer,我想等几秒钟 for (int i = 0; i < 3; i++) { // something A ... // wating [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(endTimer:)

我想等几秒钟

 for (int i = 0; i < 3; i++) {
    // something A
    ...

    // wating
    [NSTimer scheduledTimerWithTimeInterval:10
                                     target:self
                                   selector:@selector(endTimer:)
                                   userInfo:nil 
                                    repeats:YES];

    // something B

    ...
} 


- (void)endTimer:(NSTimer *)timer {
    NSLog(@"end timer");
    [timer invalidate];
}
for(int i=0;i<3;i++){
//某物
...
//等待
[NSTimer ScheduledTimer,时间间隔:10
目标:自我
选择器:@选择器(结束计时器:)
用户信息:无
重复:是];
//B什么
...
} 
-(无效)结束计时器:(NSTimer*)计时器{
NSLog(“结束计时器”);
[计时器失效];
}
我想“A->等待->B”

但是不要等待

A->B->A->B->A->B->结束计时器,结束计时器,结束计时器

有办法吗


早安

即使你的问题措辞不恰当

// set myCount somewhere as an INT with value 0
// int myCount = 0;

-(void)callA
{
    if (myCount < 3){
        [self performSelector:@selector(callB) withObject:nil afterDelay:1.0];
    }
}


-(void)callB
{
    myCount +=1;
    [self performSelector:@selector(callA) withObject:nil afterDelay:1.0];

}
//将myCount某处设置为值为0的INT
//int myCount=0;
-(无效)卡拉
{
如果(myCount<3){
[自执行选择器:@selector(callB)with object:nil afterDelay:1.0];
}
}
-(无效)callB
{
myCount+=1;
[自执行选择器:@selector(callA)with object:nil afterDelay:1.0];
}
试试这个

-(void)callA{
   //Do your thing...
}
-(void)callB{
    //Do your thing...
}
-(void)callFunction{
   count++;
   if(count<3){
     [self performSelector:@select(callA) withObject:nil];
     [NSThread sleepForTimeInterval:3.0];
     [self callB];
   }
   else{
      [timer invalidate];
   }
}

如果你不介意我说,很难理解你的要求,你应该用稍微好一点的英语来重新表述你的问题。对不起。我不会说英语。。。我在学英语。好的,你明白“接受答案”是什么意思吗?
timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(callFunction) userInfo:nil repeats:YES];