Ntimer 倒计时跳过按钮
Nstimer Countdown Skip Button
我将 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)
}
我将 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)
}