在这种情况下,timerFunc()从未被调用。我错过了什么?
class AppDelegate: NSObject, NSApplicationDelegate {
var myTimer: NSTimer? = nil
func timerFunc() {
println("timerFunc()")
}
func applicationDidFinishLaunching(aNotification: NSNotification?) {
myTimer = NSTimer(timeInterval: 5.0, target: self, selector:"timerFunc", userInfo: nil, repeats: true)
}
}
init
方法,必须使用addTimer:forMode:
将新计时器添加到运行循环中。这是文档说明中的第二个句子。否则,使用scheduledTimerWithTimeInterval
方法,这可能是您正在寻找的内容。 - Firooption
点击,你会在5秒内找到解决方案,而且甚至不用离开Xcode。 - Firo