gpt4 book ai didi

swift - 定时器只执行一次函数

转载 作者:行者123 更新时间:2023-11-28 11:01:40 26 4
gpt4 key购买 nike

所以计时器只工作一次,但在第一次工作后就不再工作了......问题是什么?如何解决?谢谢!

override func viewDidLoad() {
super.viewDidLoad()

let myTimer : Timer = Timer.scheduledTimer(timeInterval: 7, target: self, selector: (selector: "functionOne"), userInfo: nil, repeats: true)
}
}
func functionOne()
{
print("hello")

}

最佳答案

试试这段代码:

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

Timer.scheduledTimer(timeInterval: 7.0, target: self, selector: #selector(functionOne), userInfo: nil, repeats: true)

}

func functionOne () {
print("hello")
}

输出:

enter image description here

关于swift - 定时器只执行一次函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40427949/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com