我需要每分钟运行的功能。 所以我决定使用NSTimer.scheduledTimerWithTimeInterval函数
这是我的代码
override func viewWillAppear(animated: Bool) {
refreshDealData()
NSTimer.scheduledTimerWithTimeInterval(60.0, target: self, selector: Selector("runCountDownFunction:"), userInfo: nil, repeats: true)
}
func runCountDownFunction()
{
NSLog("hello World")
self.countDownTime = self.now.timeIntervalSinceDate(self.dealDateAndTime)
self.duration = Int(self.countDownTime)
self.duration = abs(self.duration)
var countDownHours = self.duration / 3600
var countDownMinutes = (self.duration % 3600) / 60
var countDownSeconds = (self.duration % 3600) % 60
var countDownDays = countDownHours / 24
var countDownHoursDisplay = countDownHours % 24
self.mCountDown.text = "\(countDownDays)D \(countDownHoursDisplay)H \(countDownMinutes)M"
}
但是我在viewWillAppear
1分钟后收到此错误*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RockStarTable.DealInsideViewController runCountDownFunction:]: unrecognized selector sent to instance 0x7f91ed8c8000'
有谁知道如何解决这个问题? 谢谢!
答案 0 :(得分:3)
您的选择器是"runCountDownFunction:"
。结肠很有意义;这意味着此方法采用一个参数。所以你必须 make 你的方法采用一个参数。像这样声明你的方法:
func runCountDownFunction(timer:NSTimer) {
现在它的签名与您在创建计时器时给出的选择器匹配。