2017-06-21 46 views
1

我家的ViewController是Tabbarcontroller如何解僱,並彈出來的ViewController同時

  • 從的TabBar我瀏覽到(A)的ViewController(TabarViewcontroller - > A(視圖 - 控制)
  • 從(視圖 - 控制)我推(B)的ViewController
  • 從B(的ViewController)我提出(C)的ViewController
  • 當我駁回(c)中的ViewController我要顯示(A)的ViewController 或(主頁)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) 

所以在C的viewController時,我辭退我想要顯示Tabbarviewcontroller或(A)ViewController

+0

你有UNwindSegue的想法?? –

回答

0

您必須通過以下方式解除ViewController C

self.presentingViewController會給出前一個視圖控制器對象。

移動到根視圖控制器

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

移動到前一個控制器

如果你需要一個視圖控制器,而不是根視圖控制器,那麼你必須只是一個popViewController

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

移動到特定視圖控制器

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>與您的目標類名稱替換。

+0

它導航到根導航控制器(登錄)我想導航到一個viewcontroller或Tabbarviewcontroller – user1374

+0

更新我的答案 – Subramanian

0

在ViewController B中,您可以編寫下面的代碼。

self.navigationController?.dismiss(animated: true, completion: { 
    self.navigationController?.popToRootViewController(animated: true) 
}) 
0

navigationController得到一個viewControllers和流行的controller

let vc = self.presentingViewController 
    if vc != nil { 
     for obj in vc.navigationController?.viewControllers{ 
      if obj is AVC { 
       self.dismiss(animated: true) { 
        vc.navigationController?.popToViewController(obj, animated: true) 
       } 

      } 
     } 
    } 
} 
0
TRY BELOW CODE 

self.navigationController?.dismiss(animated: true, completion: { 
    for controller in self.navigationController!.viewControllers as Array { 
      if controller.isKind(of: BVC) { 
       self.navigationController!.popToViewController(controller, animated: true) 
       break 
      } 
    } 

})

0

你可以做像下面。

// First, finding specific Navigation Controller and do pop. 
    if let tabBarController = presentingViewController as? UITabBarController { 
     if let navigationController = tabBarController.viewControllers?[0] as? UINavigationController { 
      navigationController.popToRootViewController(animated: false) 
      // Then, dismiss self. 
      self.dismiss(animated: true, completion: nil) 
     } 
    } 
0

當你當時在場的任何模型形成這種模式不工作彈出視圖控制器,因爲這是展示模型

的,你可以使用呈現模型父對象就像下面

let presentViewController = self.storyboard?.instantiateViewControllerWithIdentifier("PresentVC") as! PresentVC 
presentViewController.parentModel = self 
self.presentViewController(presentViewController, animated: true, completion: nil) 

並關閉視圖控制器這樣

self.dismissViewControllerAnimated(true) { 

      for controller in self.navigationController!.viewControllers as Array { 
       if controller.isKind(of: ViewControllers) { 
        parentModel.navigationController!.popToViewController(controller, animated: true) 
        break 
       } 
      } 
     } 

並在集團K彈出到你的控制器

相關問題