繁体   English   中英

无法识别的选择器使用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) {

现在,它的签名与您创建计时器时给定的选择器匹配。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM