【发布时间】:2016-02-11 10:20:37
【问题描述】:
由于未捕获的异常,我不断收到 SIGABRT 错误:
2016-02-11 01:54:23.232 time_01[1937:52731] -[time_01.ViewController increaseTime]: unrecognized selector sent to instance 0x7fdf72d12c20
2016-02-11 01:54:23.235 time_01[1937:52731] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[time_01.ViewController increaseTime]: unrecognized selector sent to instance 0x7fdf72d12c20'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e6adf45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001103d1deb objc_exception_throw + 48
2 CoreFoundation 0x000000010e6b656d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010e603eea ___forwarding___ + 970
4 CoreFoundation 0x000000010e603a98 _CF_forwarding_prep_0 + 120
5 Foundation 0x000000010ea93181 __NSFireTimer + 83
6 CoreFoundation 0x000000010e60e264 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
7 CoreFoundation 0x000000010e60de11 __CFRunLoopDoTimer + 1089
8 CoreFoundation 0x000000010e5cf821 __CFRunLoopRun + 1937
9 CoreFoundation 0x000000010e5cee08 CFRunLoopRunSpecific + 488
10 GraphicsServices 0x0000000112ca1ad2 GSEventRunModal + 161
11 UIKit 0x000000010eeca30d UIApplicationMain + 171
12 time_01 0x000000010e4d140d main + 109
13 libdyld.dylib 0x0000000110ed992d start + 1
14 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
我查看了简单计时器的代码,但不知道如何更改代码以使其不返回错误。
var timer = NSTimer()
var time = 0
@IBOutlet var timeText: UILabel!
func increaseTimer() {
time = time + 1
timeText.text = "\(time)"
}
@IBAction func play(sender: AnyObject) {
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("increaseTime"), userInfo: nil, repeats: true)
}
谢谢!
【问题讨论】:
-
Selector("increaseTime")vsSelector("increaseTimer")因为你的方法被命名为func increaseTimer() {}