由于未捕获的异常'NSInvalidArgumentException'而终止应用程序。无法识别的选择器发送到实例

问题描述 投票:0回答:1

我有点击按钮时运行的timerRunner()函数:

func timerRunner() {
        timer = Timer.scheduledTimer(timeInterval: 1.0, target: target.self, selector: (#selector(self.timeUpdater)), userInfo: nil, repeats: true)
    }

Timer.scheduledTimer的选择器选择如下:

@objc func timeUpdater() {
    counter = counter + 1

    timerLabel.text = secondConverter(seconds: counter)

}

但这是我收到的错误消息:

由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [_ SwiftValue timeUpdater]:无法识别的选择器发送到实例'

swift timer unrecognized-selector
1个回答
0
投票

据我所知,timeUpdater函数应该有一个Timer类型的参数。像这样的东西:

@objc func timeUpdater(_ timer: Timer) {
    counter = counter + 1
    timerLabel.text = secondConverter(seconds: counter)
}
© www.soinside.com 2019 - 2024. All rights reserved.