停止动作重复SwiftUI的方法



我在测试中使用以下代码,一旦用户回答了问题,就会弹出警报。然后,他们可以选择转到下一个问题或再次查看问题,然后在一段时间后出现下一个问题。

我遇到的问题是,这个动作继续到下一个问题,并在时间周期后跳过它,不允许用户有时间回答它!在下面的问题中,阻止动作自动重复的最好方法是什么?

func nextTapped() {
DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) {
nextQuestion()
}
}
func continueTapped() {
nextQuestion()
}
.alert(isPresented: $showingFeedback) {
Alert(
title: Text(scoreTitle),
message: Text(selectedQuestion!.feedback),
primaryButton: .default(Text("Review"), action: nextTapped),
secondaryButton: .default(Text("Continue"), action: continueTapped)
)
}

我发现函数传递到下一个问题。所以我回答了第一个问题,新闻回顾,10秒后它会自动转到下一个问题。我发现下一个问题也会发生这种情况,在我按下任何东西之前。我发现加上' ->

func nextTapped() -> Void {
DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) {
nextQuestion()
}
}
func continueTapped() {
nextQuestion()
}

最新更新