我在伪代码中写了一些内容,因为我不知道它的语法。我想要让timeLeftLabel.text
反映出剩下多少小时、分钟和秒钟,直到6个小时结束。我最大的问题是我不知道如何添加和减去时间。有人能帮我吗?
var timer = NSTimer()
func timerResults() {
let theDate = NSDate()
var endTime = theDate //+ 6 hours
let timeLeft = endTime //- theDate
timeLeftLabel.text = "\(timeLeft)"
}
@IBOutlet weak var timeLeftLabel: UILabel!
@IBAction func IBbtnUpdateTap(sender: UIButton){
timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("timerResults"), userInfo: nil, repeats: true)
}
@objc
关键字的目的是什么?有特定的目标还是其他什么? - Victor SiglerlabelUpdateTimerDidFire(_:)
中将OrderedDescending
更改为OrderedAscending
。此外,在startTimerButtonWasTapped
的末尾添加对labelUpdateTimerDidFire(_:)
的调用,以便在计时器启动时立即更新标签。 - rob mayoff