简体   繁体   中英

Unrecognized selector sent to instance with NSTimer.scheduledTimerWithTimeInterval function

I need the function that runs every minute. So i decided to use NSTimer.scheduledTimerWithTimeInterval function

this is my code

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"

    }

but i get this error after 1 minute from viewWillAppear

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RockStarTable.DealInsideViewController runCountDownFunction:]: unrecognized selector sent to instance 0x7f91ed8c8000'

Does anyone knows how to fix this? Thanks!

You selector is "runCountDownFunction:" . The colon is meaningful; it means this method takes one parameter . So you must make your method take one parameter. Declare your method like this:

func runCountDownFunction(timer:NSTimer) {

Now its signature matches the selector you gave when you created the timer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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