gpt4 book ai didi

ios - Ntimer 倒计时跳过按钮

转载 作者:行者123 更新时间:2023-11-30 13:08:11 27 4
gpt4 key购买 nike

我正在使用 nstimer 运行每 60 秒更改一次文本的代码。我想知道是否有人知道如何跳过 60 秒的迭代。假设用户不想阅读当前显示的文本,此时他们还需要等待 60 秒。有没有办法通过点击按钮立即进入下一个 60 秒循环?

这是我到目前为止所拥有的:

var array : String[]()

var x = 0


@IBAction func playBtnPressed(sender: UIButton)
{
update()

timer = NSTimer.scheduledTimerWithTimeInterval(60, target: self, selector: #selector(PlayVC.update), userInfo: nil, repeats: true)

}

func update()
{
if x < array.count {

let item = array[x]

aLbl.text = array.itemTitle

x += 1
}

}

@IBAction func skipBtnPressed(sender: UIButton)
{

}

预先感谢您给我的任何指导! :)

最佳答案

在您的skipBtnPressed()中,您应该首先使计时器无效,更新数据,然后设置另一个计时器。像这样

@IBAction func skipBtnPressed(sender: UIButton)
{
timer.invalidate()
update()
timer = NSTimer.scheduledTimerWithTimeInterval(60, target: self, selector: #selector(PlayVC.update), userInfo: nil, repeats: true)

}

关于ios - Ntimer 倒计时跳过按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39090188/

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