如何同时关闭和弹出视图控制器

use*_*374 7 navigation iphone uinavigationcontroller ios swift3

我的主视图控制器是 Tabbarcontroller

  • 从标签栏我导航到 (A) Viewcontroller (TabarViewcontroller -> A (Viewcontroller)
  • 从 A(视图控制器)我推(B)视图控制器
  • 从 B (Viewcontroller) i Present (C) Viewcontroller
  • 当我关闭 (c) Viewcontroller 我想显示 (A) Viewcontroller 或 (Home) TabbarviewController

所以,我想首先关闭呈现的视图控制器,然后我想弹出我以前推送的控制器

这是我的导航流程

From Tabbarviewcontroller 
1-  let aVC = self.storyboard?.instantiateViewController(withIdentifier: "a") as! OrderListingViewController
     self.navigationController?.pushViewController(aVC, animated: true)

From A viewcontroller 
2- let bVC = self.storyboard?.instantiateViewController(withIdentifier: "b") as! OrderListingViewController
     self.navigationController?.pushViewController(bVC, animated: true)

From B viewcontroller 
        let cVC = self.storyboard?.instantiateViewController(withIdentifier: "c") as! RejectOrderViewController
        cVC.providesPresentationContextTransitionStyle = true
        cVC.definesPresentationContext = true
        cVC.modalPresentationStyle=UIModalPresentationStyle.overCurrentContext
        self.tabBarController?.presentVC(cVC)
Run Code Online (Sandbox Code Playgroud)

所以从 C Viewcontroller 当我解散我想显示 Tabbarviewcontroller 或 (A) ViewController

Sub*_*n P 3

您必须ViewController C通过以下方式驳回。

self.presentingViewController将给出前一个视图控制器对象。

移动到根视图控制器

  let presentingVC = self.presentingViewController
  self.dismiss(animated: true) { 
      presentingVC?.navigationController?.popToRootViewController(animated: false)
  }
Run Code Online (Sandbox Code Playgroud)

移至上一个控制器

如果您需要以前的视图控制器而不是根视图控制器,那么您只需使用 popViewController

let presentingVC = self.presentingViewController
 self.dismiss(animated: true) {
      presentingVC?.navigationController?.popViewController(animated: false)
 }
Run Code Online (Sandbox Code Playgroud)

移动到特定的视图控制器

    let presentingVC = self.presentingViewController
    self.dismiss(animated: true) {
            if let  destinationVC =  presentingVC?.navigationController?.viewControllers.filter({$0 is <Your Destination Class>}).first {
                presentingVC?.navigationController?.popToViewController(destinationVC, animated: false)
            }
        }
Run Code Online (Sandbox Code Playgroud)

<Your Destination Class>替换为您的目标类名称。