【发布时间】:2014-09-26 11:20:47
【问题描述】:
我正在开发一个简单的计时器应用程序。我已经正确设置了我的快速桥接头并在我的视图控制器类中声明了委托协议
class SecondViewController: UIViewController, MZTimerLabelDelegate {
然后,在viewDidLoad() 之后,我为 Delegate 实现了协议:
func timerLabel(timerLabel: AnyObject!, finshedCountDownTimerWithTime countTime: NSTimeInterval){
self.startTimer.setTitle("Ok!", forState: .Normal)
}
我的MZTimerLabel 实例称为brewTimer。我不确定在哪里设置brewTimer.delegate = self。我有时也看到它以var delegate: myDelegate = //code here 的形式完成,我根本不明白。我能找到的在 Swift 中使用委托的所有示例都与两个视图控制器之间的转换有关,这不是我想要做的。
我想在我的应用程序中单击“开始”按钮,并让应用程序在计时器完成后更改按钮的标签。我启动计时器的计时器代码是这样的:
else {
brewTimer.start()
buttonSelect = 1
startTimer.setTitle("Reset", forState: .Normal)
//Start the circle counter graphic
circleCounterOuter.startWithSeconds(5)
circleCounterInner.startWithSeconds(2)
timerLabel(brewTimer, finshedCountDownTimerWithTime:5)
}
该函数的最后一行是我调用委托的协议函数的地方,但是当我单击“开始”时,标签立即变为“确定!”而不是等待finishedCountDownTimerWithTime 的 NSTimeInterval 为 5。如果有人想知道,我正在使用 cocoapod MZTimerLabel。
【问题讨论】:
标签: delegates swift delegation