如何同时关闭并弹出到ViewController [英] How to dismiss and pop to viewcontroller simultaneously

查看:142
本文介绍了如何同时关闭并弹出到ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的家庭视图控制器是Tabbarcontroller

My home viewcontroller is Tabbarcontroller

  • 从选项卡中,我导航到(A)Viewcontroller(TabarViewcontroller ->一个(Viewcontroller)
  • 从A(Viewcontroller)中我按下(B)Viewcontroller
  • 从B(Viewcontroller)到当前(C)Viewcontroller
  • 当我关闭(c)Viewcontroller时,我想显示(A)Viewcontroller 或(主页)TabbarviewController
  • From tabbar i navigate to (A) Viewcontroller (TabarViewcontroller -> A (Viewcontroller)
  • From A (Viewcontroller) i push (B) Viewcontroller
  • From B (Viewcontroller) i Present (C) Viewcontroller
  • When i dismiss (c) Viewcontroller i want to show (A) Viewcontroller or (Home) TabbarviewController

因此,我想先关闭显示的viewcontroller,然后再弹出以前的推入控制器

So, I want to first dismiss presented viewcontroller and then I want to pop my previous pushed 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.

You have to dismiss the ViewController C in the following way.

self.presentingViewController将提供上一个视图控制器对象.

self.presentingViewController will give the previous view controller object.

移至根视图控制器

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

移至上一个控制器

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

If you need to previous view controller instead of root view controller then you have to just to a 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>替换为目标类名称.

<Your Destination Class> replace with your destination class name.

这篇关于如何同时关闭并弹出到ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆