ios - 如何同时关闭并弹出到 View Controller

标签 ios iphone swift3 uinavigationcontroller navigation

我的主视图 Controller 是Tabbarcontroller

  • 从选项卡栏导航到 (A) Viewcontroller (TabarViewcontroller -> A( View Controller )
  • 从 A(Viewcontroller)我推送(B)Viewcontroller
  • 来自 B(Viewcontroller)我现在(C)Viewcontroller
  • 当我关闭 (c) Viewcontroller 时,我想显示 (A) Viewcontroller 或(主页)TabbarviewController

所以,我想首先关闭呈现的 View Controller ,然后弹出我之前推送的 Controller

这是我的导航流程

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)

所以当我关闭时,从 C Viewcontroller 中我想显示 Tabbarviewcontroller 或 (A) ViewController

最佳答案

您必须忽略 ViewController C通过以下方式。

self.presentingViewController将给出前一个 View Controller 对象。

移动到 Root View Controller

  let presentingVC = self.presentingViewController
  self.dismiss(animated: true) { 
      presentingVC?.navigationController?.popToRootViewController(animated: false)
  }

移至上一个 Controller

如果您需要以前的 View Controller 而不是 Root View Controller ,那么您只需使用 popViewController

let presentingVC = self.presentingViewController
 self.dismiss(animated: true) {
      presentingVC?.navigationController?.popViewController(animated: false)
 }

移动到特定的 View Controller

    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)
            }
        }

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

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

相关文章:

ios - 将ios应用上传到AppStore时出错

ios - 如何在 Swift 中从 NSmutableArray 的索引之一(lat lng 坐标)对 NSmutableArray 进行排序

iphone - iOS 开发 : What are some ways I can troubleshoot a lag issue in my game that occurs 15 - 30 minutes after playing it?

iphone - 在Cocos2d中在屏幕上画一条直线?

swift - Swift 3 中的 NSCoding - 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因 : '-[AppName. 用户encodeWithCoder:]

ios - 使用 CocoaPods 安装 MapBoxNavigation 后出现 Swift 编译器错误问题

ios - 创建多个 UIButtons 但只有最后一个可见

iphone - 使用 SQLite for iPhone 从数据库中获取字符串

iphone - 核心数据优化

ios - 使用 Swift 检查在 ios 上运行的应用程序