【发布时间】:2014-11-19 09:39:20
【问题描述】:
我有一个工作倒计时,您可以通过按下添加按钮来增加倒计时,这就是倒计时的时间(所以基本上用户可以设置倒计时)
我想将开始时间显示为 00:00,就像在我的标签中一样。
当我单击按钮增加倒计时时,它显然从 1 开始,因为此时它只是一个 Int
我可以创建一个数组并增加单个索引,然后在我的标签中显示它们吗?
任何人都可以帮助解决这个问题,或者从下面的内容中向我指出编写代码的方向 谢谢
var timeArray: [Double : Double] = [00, 00]
var timer = NSTimer()
var countdown = 0
func runTimer() {
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self,
selector:Selector("updateTimer"), userInfo: nil, repeats: true)
}
func updateTimer() {
if countdown > 0 {
countdown--
TimerLabel.text = String(countdown)
} else {
countdown = 0
TimerLabel.text = String(countdown)
}
}
@IBOutlet weak var TimerLabel: UILabel!
@IBAction func IncreaseCountdown(sender: AnyObject) {
countdown++
TimerLabel.text = String(countdown)
}
@IBAction func StartCountdown(sender: AnyObject) {
runTimer()
}
@IBAction func StopCountdown(sender: AnyObject) {
timer.invalidate()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
【问题讨论】:
标签: ios objective-c arrays swift nstimer