简体   繁体   English

呈现警报控制器后,TableView(didSelectRowAt IndexPath)中的快速继续流

[英]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.

相关问题 ViewController 在出现警报时重新加载 controller swift - ViewController reloads on presenting alert controller swift 如何快速从故事板中的 didSelectRowAt indexPath 打开视图标签栏控制器? - How to open view tabbar controller from didSelectRowAt indexPath within storyboard in swift? Swift 3将单元格数据A视图传递到B视图,有趣的是didSelectRowAt indexPath在选择行后崩溃 - Swift 3 pass the cell data A view to B view, with fun didSelectRowAt indexPath crash after select row 将tapGesture添加到tableView然后无法执行tableView(_ tableView:UITableView,didSelectRowAt indexPath:IndexPath)方法 - Add tapGesture to tableView then can not perform tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) method 在 tableView didSelectRowAt indexPath iOS 之前准备 segue 调用 - prepare for segue call before tableView didSelectRowAt indexPath iOS tableView(_ tableView:UITableView,didSelectRowAt indexPath:IndexPath)将UITapGestureRecognizer添加到自定义UITableViewCell时不起作用 - tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) Doesn't work when I add a UITapGestureRecognizer to my custom UITableViewCell Swift - didSelectRowAt indexPath 下一个 VC 没有出现/没有故事板/ - Swift - didSelectRowAt indexPath next VC not showing up /no storyboards/ swift访问tableview indexPath ouside - swift access tableview indexPath ouside Swift - TableView 将 IndexPath 返回为 nil - Swift - TableView is returning the IndexPath as nil 迅速超出范围…与tableView [indexPath] - Swift out of range… with tableView[indexPath]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM