
使用简单的Action设置定时器
- (IBAction)timerStart:(ID)sender {if(!secondCounter == 0){ [countdownTimer invalIDate]; } else { [self setTimer]; }} 定时器代码
- (voID)timerRun { secondCounter = secondCounter - 1; int minutes = secondCounter; Nsstring *timerOutput = [Nsstring stringWithFormat:@"%d",minutes ]; countDownLabel.text = timerOutput; if(secondCounter == 0){ [countdownTimer invalIDate]; countdownTimer = nil; }}- (voID)setTimer { secondCounter = 60; countdownTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerRun) userInfo:nil repeats:YES];}解决方法 你什么意思停止计时器?计时器不会停止.你想让countDownLabel.text显示60?当您使计时器无效时,它将停止运行并调用timerRun方法如果要重新启动计时器,只需再次调用setTimer函数.我想你的意思是在[countdownTimer invalIDate]之后有countDownLabel.text = @“60”;当您再次单击该按钮时,计时器将再次启动并更改标签.如果这是您正在寻找的,请告诉我. 正如Christian所说,你必须重置第二个计数器
secondCounter = 0;总结
以上是内存溢出为你收集整理的ios – 停止并重置NSTimer全部内容,希望文章能够帮你解决ios – 停止并重置NSTimer所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)