我有一个名为 Util.swift 的文件,其中包含以下内容
class foo: NSObject {
func sayHello() {
print("hello")
}
}
var globalTimer = NSTimer()
func startTheTimer() {
globalTimer = NSTimer.scheduledTimerWithTimeInterval(2.0, target: foo.self, selector: Selector("sayHello"), userInfo: nil, repeats: true)
}
当我在任何 viewController 的 viewDidLoad 中调用 startTheTimer() 时,我收到一条错误消息“无法识别的选择器发送到类”。我不知道我在这里做错了什么。
最佳答案
class func sayHello() {
print("hello")
}
请将此设为类方法。
关于ios - Xcode NSTimer 错误 : Unrecognized selector sent to class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36417855/