【问题标题】:How to dismiss multiple present view controllers?如何关闭多个当前视图控制器?
【发布时间】:2021-05-21 19:57:57
【问题描述】:

如果我的应用程序有这样的流程..

navigation(vc1) --pushed--> vc2 --present--> navigation(vc3) --push-- > vc4 --push--> vc5

如何解散到 vc2 ?

【问题讨论】:

标签: ios swift uinavigationcontroller presentviewcontroller dismissviewcontroller


【解决方案1】:

你可以使用popToViewController:

基本设置:

let nav = UINavigationController()
let vc1 = UIViewController()
vc1.title = "vc1"
let vc2 = UIViewController()
vc2.title = "vc2"
let vc3 = UIViewController()
vc3.title = "vc3"
let vc4 = UIViewController()
vc4.title = "vc4"
nav.viewControllers = [vc1,vc2,vc3,vc4]

然后弹出到vc2(在数组中的索引1处):

let vcs = nav.viewControllers
nav.popToViewController(vcs[1], animated: true)
//OR, if you still have a reference to the view controller
nav.popToViewController(vc2, animated: true)

【讨论】:

    猜你喜欢
    • 2019-05-30
    • 2014-09-10
    • 2014-10-03
    • 2018-11-27
    • 2019-07-03
    • 2017-07-09
    • 2016-11-27
    • 2021-09-28
    • 1970-01-01
    相关资源
    最近更新 更多