早教吧作业答案频道 -->其他-->
iOS如何在一个函数执行过程中,在某一步停下来,等待一个消息,或通知之类的东西,然后继续执行就如同做一个nstimer,把那个固定时间改成一个条件.求教.
题目详情
iOS 如何在一个函数执行过程中,在某一步停下来,等待一个消息,或通知之类的东西,然后继续执行
就如同做一个nstimer,把那个固定时间改成一个条件.求教.
就如同做一个nstimer,把那个固定时间改成一个条件.求教.
▼优质解答
答案和解析
用线程吧 貌似没又windows下边的messagebox那样的函数
-(void)timerArrived:(id)sender{
timerFinished = YES;
}
-(void) waitTimeForSeconds:(NSTimeInterval) times{
timerFinished = NO;
NSTimer *delayForProgram = [NSTimer scheduledTimerWithTimeInterval:times target:self selector:@selector(timerArrived:) userInfo:nil repeats:NO];
while (!timerFinished) {
[[NSRunLoop currentRunLoop] addTimer:delayForProgram forMode:@"NSDefaultRunLoopMode"];
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[[NSDate alloc] initWithTimeIntervalSinceNow:times]];
}
[delayForProgram release];
}
这里时间按秒计算 当然也可以无止尽等待
-(void)timerArrived:(id)sender{
timerFinished = YES;
}
-(void) waitTimeForSeconds:(NSTimeInterval) times{
timerFinished = NO;
NSTimer *delayForProgram = [NSTimer scheduledTimerWithTimeInterval:times target:self selector:@selector(timerArrived:) userInfo:nil repeats:NO];
while (!timerFinished) {
[[NSRunLoop currentRunLoop] addTimer:delayForProgram forMode:@"NSDefaultRunLoopMode"];
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[[NSDate alloc] initWithTimeIntervalSinceNow:times]];
}
[delayForProgram release];
}
这里时间按秒计算 当然也可以无止尽等待
看了iOS如何在一个函数执行过程中...的网友还看了以下:
如图为中心法则图解.下列有关的叙述中,错误的是()A.过程a只发生在有丝分裂的间期B.过程b和c为 2020-05-13 …
汽车拉力赛有两个距离相等的赛程.第一赛程由平路出发,离中点26千米处开始上坡;通过中点行驶4千米后 2020-05-13 …
假设U=F(G(X)+Y),其中Y=Y(X)由方程Y方+e的y方=SIN(X+Y)确定,而且F,G 2020-05-14 …
如图是绿色植物叶肉细胞中光合作用与需氧呼吸过程及其关系的图解,其中A-D表示相关过程,a-e表示有 2020-05-14 …
如图是植物某细胞中光合作用与有氧呼吸过程及其关系的图解,其中A-D表示相关过程,a-e表示有关物质 2020-05-14 …
已知微分方程y''+y=x的一个解为y1=x,微分方程y''+y=e^x的一个解为y2=(1/2) 2020-06-02 …
求方程xdy+dx=e^ydx的通解移位:dy/(1-e^y)+dx/x=0∫(1+(e^y/(1 2020-06-12 …
一口枯井深64米,井底之蛙想从井底爬上来,第一天白天,它往上爬到井下一半时,晚上又滑落了白天所爬路 2020-06-26 …
过点A(0,a)作直线与圆E(x-2)²+y²=1交于B,C两点,在B,C上取满足 2020-06-27 …
求微分方程的特解求微分方程cosydx+[1+e^[-(x)]sinydy=0,y(0)=π/4 2020-06-27 …