我正试图设置一个定时器来定期运行事件,如here所描述的那样。我知道hashtag参数已被弃用,因此我尝试相应地重写startTimer代码:
func startTimer()
{
let theInterval: NSTimeInterval = 5.0
self.timer = NSTimer.scheduledTimerWithTimeInterval
(
interval: theInterval,
target: self,
selector: Selector("timerTick:"),
userInfo: "Hello!",
repeats: true
)
}问题是,我一直收到错误:“对成员'scheduledTimerWithTimeInterval( _:invocation:repeats:)‘的模糊引用”。但我不是试图运行scheduledTimerWithInterval:target:selector:userInfo:repeats. ( _:invocation:repeats:),而是运行scheduledTimerWithTimeInterval我认为从我传递的参数来看,这是显而易见的。
我需要做什么改变呢?
发布于 2016-07-25 17:14:23
有两个问题:
scheduledTimerWithTimeInterval和开括号之间的换行符和空格搞混了。所以,你可以:
timer = NSTimer.scheduledTimerWithTimeInterval(
2.0,
target: self,
selector: #selector(timerTick(_:)),
userInfo: "Hello!",
repeats: true
)注意,我还将Selector("timerTick:")替换为#selector语法。
https://stackoverflow.com/questions/38573524
复制相似问题