【发布时间】:2023-03-04 11:23:01
【问题描述】:
我在一个接一个地显示多个警报控制器时遇到问题。我想做的是让我的 for 循环等到用户关闭响应控制器。 我的显示消息代码如下。
for block in blocks {
self.presentMessage(title: codeBlock.stringInput1, message: codeBlock.stringInput2)
}
func presentMessage(title: String, message: String, completion: @escaping (Bool)->()) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Done", style: .default, handler: { action in
completion(true)
}))
self.present(alert, animated: true)
}
编辑 --
这是我的块类
class block: Codable {
var type: String
var stringInput1: String
var stringInput2: String
init(t: String, i1: String, i2: String) {
type = t
stringInput1 = i1
stringInput2 = i2
}
}
我已经尝试使用调度组,但未能使其正常工作。我设置的最终目标是让块能够根据块的类型执行不同的操作。 如果可能的话,我想让我的 for 循环等待函数完成,直到它继续。
【问题讨论】: