首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“对成员'scheduledTimerWithTimeInterval( _:invocation:repeats:)‘的模糊引用”

“对成员'scheduledTimerWithTimeInterval( _:invocation:repeats:)‘的模糊引用”
EN

Stack Overflow用户
提问于 2016-07-25 16:56:19
回答 1查看 1.1K关注 0票数 1

我正试图设置一个定时器来定期运行事件,如here所描述的那样。我知道hashtag参数已被弃用,因此我尝试相应地重写startTimer代码:

代码语言:javascript
复制
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我认为从我传递的参数来看,这是显而易见的。

我需要做什么改变呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-25 17:14:23

有两个问题:

  1. 它被scheduledTimerWithTimeInterval和开括号之间的换行符和空格搞混了。
  2. 不应提供第一个参数标签。

所以,你可以:

代码语言:javascript
复制
timer = NSTimer.scheduledTimerWithTimeInterval(
    2.0,
    target: self,
    selector: #selector(timerTick(_:)),
    userInfo: "Hello!",
    repeats: true
)

注意,我还将Selector("timerTick:")替换为#selector语法。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38573524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档