scheduleTimerWithTimeInterval

scheduleTimerWithTimeInterval

本文介绍了调用中的额外参数“选择器" - NSTimer scheduleTimerWithTimeInterval的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码行:

changeColour = NSTimer.scheduledTimerWithTimeInterval(TIMES, target: self, selector: "changeColourOfPage", repeats: true)

但它给出了错误调用中的额外参数'选择器'"

but it gives the error "Extra argument 'selector' in call"

当我将 TIMES 变量更改为类似 1.0 的数字时,它工作正常.变量 TIMES 设置为 1.0.

when I change the TIMES variable to a number like 1.0, it works fine. The variable TIMES is set to 1.0.

这只是一个小故障,还是我对某事很愚蠢?我需要用它来随机运行一个方法.

Is this just a glitch, or am I being stupid about something?I need to use it to run a method at random intervals.

请帮忙!

推荐答案

您似乎缺少 userInfo 参数.试试这个:

It looks like you're missing the userInfo argument. Try this:

Swift 2

let TIMES = 1.0
var changeColour = NSTimer.scheduledTimerWithTimeInterval(TIMES, target: self, selector: "restart", userInfo: nil, repeats: true)

斯威夫特 3、4、5

let TIMES = 1.0
var changeColour = Timer.scheduledTimer(timeInterval: TIMES, target: self, selector: #selector(restart), userInfo: nil, repeats: true)

这篇关于调用中的额外参数“选择器" - NSTimer scheduleTimerWithTimeInterval的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:01