【问题标题】:Not able to pass Timer.sheduledTimer with parameters [duplicate]无法通过参数传递 Timer.sheduledTimer [重复]
【发布时间】:2018-05-15 14:20:22
【问题描述】:
basicPidTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.pidsUsage(indexPid:)), userInfo: pidsIndex, repeats: false)

//调用下面的方法但没有触发任何帮助?

@objc func pidsUsage(indexPid : Int){

}

【问题讨论】:

    标签: ios swift nstimer


    【解决方案1】:

    参数的类型必须是Timer。即

    @objc func pidsUsage(timer : Timer) {
    
    }
    

    【讨论】:

    • k,但是我如何传递更新后的 indexPid 值?
    • 在计时器的.userInfo 属性中?
    • po sender.userInfo![0] 。在读取 userinfo 时得到这个 .. 错误::3:16: error: type 'Any' has no subscript members sender.userInfo![0]
    • 你需要投射它。 (timer.userInfo as! [Int])[0]
    • 谢谢...我是这样做的,让userInfo = sender.userInfo 为!字典
    猜你喜欢
    • 1970-01-01
    • 2014-03-17
    • 2011-07-31
    • 1970-01-01
    • 2017-03-21
    • 2011-12-18
    • 2020-07-12
    • 1970-01-01
    • 2021-04-24
    相关资源
    最近更新 更多