我想每五个按钮调用一次函数。我目前有在计时器上调用的函数,但这不是很好的经验。
不确定从哪里开始。这是我当前的代码:
override func viewDidLoad() {
super.viewDidLoad()
@IBAction func nextButtonPressed(_ sender: Any) {
}
func displayMasteredWords() {
masteredWordsView.isHidden = false
masteredWordsView.text = "You just mastered:\(readString)"
}
答案 0 :(得分:2)
您可以保留呼叫总数。每次将此数字除以5时,您就会呼叫displayMasteredWords
。
class Controller: UIViewController {
private var numCalls = 0
@IBAction func nextButtonPressed(_ sender: Any) {
numCalls += 1
if numCalls % 5 == 0 {
displayMasteredWords()
}
}
private func displayMasteredWords() {
masteredWordsView.isHidden = false
masteredWordsView.text = "You just mastered:\(readString)"
}
}