[英]Swift Continue Flow in TableView(didSelectRowAt IndexPath) after presenting Alert Controller
I'm wanting to present an UIAlertController when a user taps a row in a tableView when condition
isn't equal to 1. Once the alert is dismissed, I'm wanting the remaining code in didSelectRowAt IndexPath
to execute. 当condition
不等于1时,当用户在tableView中点击一行时,我想提供一个UIAlertController。一旦解除警报,我didSelectRowAt IndexPath
执行didSelectRowAt IndexPath
的其余代码。 However, the flow stops. 但是,流程停止。 I assume I'm needing something other than nil
in completion:
but I'm stumped. 我想我需要除nil
其他东西completion:
但是我很沮丧。
I'm presenting the Alert Controller like so: 我正在像这样呈现警报控制器:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if condition != 1 {
let alertController = UIAlertController(title: "Title", message: "message", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(defaultAction)
present(alertController, animated: true, completion: nil)
condition = 1
}
\\remaining code to be executed
}
You can put the code to be executed in the action handler of the defaultAction. 您可以将要执行的代码放在defaultAction的动作处理程序中。 Thus the code will be executed after the ok button is pressed. 因此,代码将在按下确定按钮后执行。 If you put it in present() method completion, it will be executed exact after the alert is presented. 如果将其放在present()方法完成中,则将在显示警报后准确执行它。
let alert = UIAlertController(title: "Hello", message: "Nai", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action) in
print("Executed after ok tapped")
}))
present(alert, animated: true) {
print("Executed when its presented")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.