gpt4 book ai didi

ios - 关闭并弹出一个 View Controller

转载 作者:搜寻专家 更新时间:2023-10-31 08:23:51 25 4
gpt4 key购买 nike

我想在我的 View Controller 堆栈上返回两个级别。我按此顺序有三个 segue:Show、Show、Present Modally。有一个导航 Controller 正在使用中。从我的第 4 个 View 我想回到第 2 个 View 。我试过使用 self.presentingViewController?.presentingViewController?.navigationController?.popViewControllerAnimated(false);

self.presentingViewController?.presentingViewController?.dismissViewControllerAnimated(false, completion: nil);

第二个仅在第二个和第三个 segues 为“Present Modally”时才有效。我怎样才能让他们在解雇和流行的情况下工作?

最佳答案

尝试在弹出其他两个之前关闭呈现的 View Controller :

func dismissThenDoublePop() {

// Get the presenting/previous view
let previousView = self.presentingViewController as UINavigationController

// Dismiss the current view controller then pop the others
// upon completion
self.dismissViewControllerAnimated(true, completion: {

// Get an array of the current view controllers on your nav stack
let viewControllers: [UIViewController] = previousView.viewControllers as [UIViewController];

// Then either pop two view controllers, i.e. pop
// to viewControllers[viewControllers.count - 2], or
// pop to the second view controller in the nav stack,
// i.e. viewControllers[1]. (In this case I've used the
// first option.)
self.navigationController!.popToViewController(viewControllers[viewControllers.count - 2], animated: true);

});
}

关于ios - 关闭并弹出一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27535967/

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