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

标签 swift timer unrecognized-selector

我有 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)

}

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

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue timeUpdater]: unrecognized selector sent to instance '

最佳答案

据我所知,timeUpdater函数应该有一个Timer类型的参数。 类似这样的事情:

@objc func timeUpdater(_ timer: Timer) {
    counter = counter + 1
    timerLabel.text = secondConverter(seconds: counter)
}

关于swift - 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序。无法识别的选择器发送到实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52394500/

相关文章:

ios - Collection View 单元格缩放不重置

android - 什么时候不碰一会儿 Activity ?

ios - [UIBarButtonItem 转换点 :toView:]: unrecognized selector sent to instance

ios - 无法识别无法识别的选择器错误的原因

iOS FBSDK v4 loginbuttondidlogout 无法识别的选择器

ios - 在收集单元格中添加背景 View

ios - 如何在代码中使用 UItable 单元格中的按钮导出

ios - MapBox 安装问题

java - Android Chronometer 倒计时完成

java - 定时器任务只运行一次