gpt4 book ai didi

ios - 转到导航堆栈中的上一个 Controller (Swift)

转载 作者:可可西里 更新时间:2023-11-01 00:23:47 24 4
gpt4 key购买 nike

我正在尝试在 alertView 之后将导航堆栈中的前一个 View Controller 弹出 View Controller 。截至目前,我的程序不会运行 popViewController 方法,因为 alertView 挡住了路,并引发了错误:

    UINavigationController 0x17670900 while an existing transition or presentation is occurring; the navigation stack will not be updated.

在用户从 alertView 中单击“确定”后,我如何着手运行 popViewController 方法?我是否必须设置一个委托(delegate)来检测用户何时单击“确定”?

这是我的代码:

    //alertView after Picture saved
let alertView = UIAlertController(title: "Success!", message: "Record Saved to Database", preferredStyle: .Alert)
alertView.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil))

self.presentViewController(alertView, animated: true, completion: nil)

//go to previous controller using popViewController, doesnt work, brings up error message
if let navController = self.navigationController {
navController.popViewControllerAnimated(true)
}

最佳答案

当用户从 AlertView 按下 Ok 按钮时,您需要弹出 View Controller 。

let alertView = UIAlertController(title: "Success!", message: "Record Saved to Database", preferredStyle: .Alert)
let OKAction = UIAlertAction(title: "Ok", style: .Default) { (action) in
// pop here
if let navController = self.navigationController {
navController.popViewControllerAnimated(true)
}
}
alertView.addAction(OKAction)
self.present(alertView, animated: true, completion: nil)

关于ios - 转到导航堆栈中的上一个 Controller (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31365824/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com