簡體   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