由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序。发送到实例的无法识别的选择器
Terminating app due to uncaught exception 'NSInvalidArgumentException'. unrecognized selector sent to instance
我有 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)
}
我有 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)
}