【问题标题】:Swift 3 how to dismiss UIViewController after UIAlertController actionSwift 3 如何在 UIAlertController 操作后关闭 UIViewController
【发布时间】:2017-03-22 19:54:42
【问题描述】:

我有一个警报控制器,想在按下 OK 后关闭视图控制器,但不知道怎么做。 self.dismiss(animated: true) 只关闭警报控制器本身。这是我的代码。

let alertController: UIAlertController = UIAlertController(title: "Password updatd", message: "Your password has been changed successfully", preferredStyle: .alert)

let okAction: UIAlertAction = UIAlertAction(title: "OK", style: .default) { action -> Void in }

alertController.addAction(okAction)

self.present(alertController, animated: true, completion: nil)

我试过这个,它只删除了当前的视图控制器,但没有回到根视图控制器。

let okAction: UIAlertAction = UIAlertAction(title: "OK", style: .default) { action -> Void in
self.navigationController?.popToRootViewController(animated: true)}

这给了我一个警告expression of type UIViewController is unused

【问题讨论】:

    标签: swift3 uialertcontroller


    【解决方案1】:

    导航控制器:

    前任控制器

    self.navigationController?.popViewController(animated: true)
    

    根控制器

    self.navigationController?.popToRootViewController(animated: true)
    

    模态视图控制器:

    self.dismiss(animated: true, completion: nil)
    

    【讨论】:

    • 我没有故事板。
    • 好的,那你用的是Xib的?
    • 如何呈现另一个 ViewController?我在以编程方式创建一切方面并不是很先进,但我想学习
    • 在上方查看我的编辑
    • 试试这个以及你最近收到的错误stackoverflow.com/questions/37843049/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-08
    • 2016-04-05
    • 2023-03-29
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多