Tag: çios nstimer

我怎样才能用这个简单的while循环使用NSTimer?

我有一个 – (void)方法正在执行,并在一个点上得到一个while循环,直接从加速度计获取值的那一刻 我在整个关于NSTimer类的文档中进行了讨论,但我无法理解我在这种情况下如何使用这个对象: 例如 -(void) play { …… … if(accelerationOnYaxis >0 && accelerationOnYaxis < 0.9 ) { startTimer; } while(accelerationOnYaxis >0 && accelerationOnYaxis < 0.9) { if(checkTimer >= 300msec) { printOut_AccelerationStayedBetweenThoseTwoValuesForAtLeast300msecs; break_Out_Of_This_Loop; } } stopTimerAndReSetTimerToZero; ….. more code… …. … } 任何帮助?

在Objective-C中实现倒数计时器?

我是iOS编程新手。 我正在研究匹配游戏的单词。 在这个游戏中,我需要实现时间计数器,显示分钟和秒。 我希望当我的比赛开始时我的计时器开始3分钟。 现在我想用秒来反向减less这个定时器。 我的代码只是数秒钟..这里是我的代码: secondsLeft–; int seconds = (secondsLeft %3600) % 60; Timerlbl.text = [NSString stringWithFormat:@"%02d",seconds]; if (seconds==0) { UIAlertView *pAlert = [[UIAlertView alloc]initWithTitle:@"Sorry!!" message:@"TimeOver" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel",nil]; [pAlert show]; [pAlert release]; } } 在Viewdidload中,我通过计时器来调用它。 countDown=[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(TimeOver) userInfo:nil repeats:YES]; 请任何人指导我如何在两分钟内做到这一点。