使用 NSTimer.scheduledTimerWithTimeInterval 函数发送到实例的无法识别的选择器

Unrecognized selector sent to instance with NSTimer.scheduledTimerWithTimeInterval function

我需要每分钟运行一次的函数。 所以我决定使用 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'

有谁知道如何解决这个问题? 谢谢!

您的选择器是 "runCountDownFunction:"。冒号是有意义的;这意味着此方法采用 一个参数 。所以你必须你的方法接受一个参数。像这样声明你的方法:

func runCountDownFunction(timer:NSTimer) {

现在它的签名与您在创建计时器时提供的选择器匹配。