我有两个函数运行,名为updatePrice和updateTime,当我点击一个UIButton时,我想停止它们。如何停止使用Swift的UIButton函数的另一个函数?
func updateTime() {...}
func updatePrice() {...}
// ..
@IBAction func Button(sender: UIButton) {
// What should I write here?
}
我有两个函数运行,名为updatePrice和updateTime,当我点击一个UIButton时,我想停止它们。如何停止使用Swift的UIButton函数的另一个函数?
func updateTime() {...}
func updatePrice() {...}
// ..
@IBAction func Button(sender: UIButton) {
// What should I write here?
}
做一些像NSOperation
s做:做一个布尔值并定期在这些函数中检查它。喜欢的东西:
var stopFuncs = false
在敏感时刻功能
后来插入:
if stopFuncs { return }
这添加到按钮的代码:
stopFuncs = true
如果'updateTime'和'updatePrice'运行在主线程中,'Button'甚至不会在调用完成后才被调用... – nhgrif
所有的都在ViewController类中 –