while循环使用NSTimer
我想创build一个运行的NSTimer可以说10分钟。 然后我想在延迟10分钟的时间之后写一个while循环,之后执行这行。 例如。
NSTimer * countDown = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector userInfo:nil repeats:NO]; while (countDown == stil running (hasnt reached 10 minute mark) ){ // kill 10 minutes of time }//when 10 minutes is up execute next line of code
第一
scheduledTimerWithTimeInterval:
方法的timeInterval参数以秒为单位。 如果你想在几分钟内,不要忘了乘以60
。
第二
你为什么要这样等待呢? 只需要在NSTimer
触发的select器中,在10分钟之后调用要执行的行。
NSTimer * countDown = [NSTimer scheduledTimerWithTimeInterval:(10.0 * 60) target:self selector:@selector(tenMinutesLater) userInfo:nil repeats:NO];
接着
-(void)tenMinutesLater { //put some code here. This will be executed 10 minutes later the NSTimer was initialized }
而不是一个while循环,只需在第一个定时器所调用的方法内创build一个新的定时器即可。
NSTimer *countDown = [NSTimer scheduledTimerWithTimeInterval:600 target:self selector:@selector(startSecondTimer) userInfo:nil repeats:NO]; - (void)startSecondTimer { NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:600 target:self selector:@selector(doSomething) userInfo:nil repeats:NO]; }
PS,时间间隔以秒为单位 – 10分钟= 600秒,而不是10秒。
- 如何从Facebook注销
- Curiosity.letsGetSwift.sorted()
- 如何从MPRemoteCommandCenter禁用所有MPRemoteCommand对象
- 将UIPageControl添加到UIScrollView
- commitEditingStyle:删除数据,但继续显示行
- 在哪里可以找到Apple iAP中有关SSServerErrorDomain的描述?
- 如何使UINavigationBar中的UISearchBar仅使用块animation调整左边距?
- parsingAPI – Facebooklogin无法在iPhone设备上工作
- 如何在Swift for iOS中正确使用CFNotificationCenterAddObserver