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];