ios - 呈现新的 ViewController 后 Swift 关闭当前的 ViewController
问题描述
我的场景,我正在尝试创建多个present ViewController
. 在这里,在我需要关闭以前的 ViewController 之后呈现新的 ViewController。
ViewController A (RootViewController)
下一步按钮单击以呈现,ViewController B
然后查看控制器 B 下一步按钮单击以呈现ViewController C
。现在,如果我关闭 ViewController C 需要显示ViewController A
.
解决方案
这是您可以继续的方法,
class VCA: UIViewController {
@IBAction func onTapNextButton(_ sender: UIButton) {
if let controller = self.storyboard?.instantiateViewController(withIdentifier: "VCB") as? VCB {
self.present(controller, animated: true, completion: nil)
}
}
}
由于VCC
嵌入在 a 中UINavigationController
,因此您需要呈现UINavigationController
而不是VCC
.
对于这个子类并将UINavigationController
其设置class
为UINavigationController
.storyboard
class VCB: UIViewController {
@IBAction func onTapNextButton(_ sender: UIButton) {
if let controller = self.storyboard?.instantiateViewController(withIdentifier: "NavVC") {
self.dismiss(animated: false, completion: nil)
self.presentingViewController?.present(controller, animated: true, completion: nil)
}
}
}
class NavVC: UINavigationController {}
class VCC: UIViewController {
@IBAction func onTapCloseButton(_ sender: UIButton) {
self.navigationController?.dismiss(animated: true, completion: nil)
}
}
推荐阅读
- windows - 将日志文件从 linux 服务器复制到 windows 共享服务器的脚本
- python - 如何将`mpl_connect`限制为`axes`而不是整个`figure`?
- curl - Autodesk Forge - 使用 curl 下载文件
- python - 如何使用 python 连接到 Microsoft Project Online
- flutter - 用状态重置计数器
- html - 增加输入框 HTML 中下拉列表的字体大小
- python - ArcPy AttributeError: 'module' object has no attribute 'FromGeohash'
- java - Intent dont workin android studio
- ansible - Ansible:将字符串附加到文件中的现有行
- kml - 我可以设置高度模式或全局拉伸(仅一次)吗?