ios - 在 swift 4 中自动关闭 View Controller

标签 ios swift

假设我有 3 个标记为“A”、“B”和“C”的 ViewControllers。现在,“A”是窗口的 rootViewController,它以模态方式呈现“B”。当在“B”中点击一个按钮时,它应该立即以模态方式呈现 C 并自动关闭“B”。我怎样才能做到这一点?我在 StackOverflow 中看到了所有示例,但它们不起作用

@IBAction func proceedBtnTapped(_ sender: Any) {
    weak var pvc = self.presentingViewController
    let vc = ThirdViewController()

    pvc?.present(vc, animated: true, completion: { [weak self] in
        self?.dismiss(animated: true, completion: nil)
    })
}

这是我的代码。有帮助吗?

最佳答案

首先关闭您的b View Controller ,然后在A 上呈现c View Controller 。

试试这个。

let vc = ThirdViewController()
let navVC = UINavigationController(rootViewController: vc)

if let parent = self.presentingViewController{
    self.dismiss(animated: true){
         parent.present(navVC, animated: true)
    }
}

关于ios - 在 swift 4 中自动关闭 View Controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49234141/

相关文章:

ios - 如何更改 iOS 中 JTCalenderView 的工作日顺序?

iOS - 串行通信集成到 Xcode 项目中

ios - 如何在 ios 应用程序商店的 Release模式下构建 React Native 应用程序?

swift - 节省字节 Vapor Swift

ios - Swift 2 - 定时 Action 间隔一秒?

Swift 3 在 if 中展开并比较 int

swift - iOS 应用无法识别我的信标

iphone - 选项卡推送通知 cocos2d 游戏崩溃

javascript - Node.js 应用程序到 iOS 应用程序?

ios - Swift - NSHTTPCookie 为零