我的主视图控制器是Tabbarcontroller
所以,我想首先解除显示的viewcontroller,然后我想弹出我之前推送的控制器
这是我的导航流程
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 :(得分: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>
替换您的目标类名称。
答案 1 :(得分:0)
在ViewController B中,您可以编写以下代码。
self.navigationController?.dismiss(animated: true, completion: {
self.navigationController?.popToRootViewController(animated: true)
})
答案 2 :(得分: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
}
}
})
答案 3 :(得分:0)
你可以这样做。
C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng
答案 4 :(得分: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
}
}
}
并以块弹出到您的控制器
答案 5 :(得分:0)
我必须使用NotificationCenter来弹出以前的控制器。
let back_view = Notification.Name("back_view")
//这是关闭实际控制器的动作
@IBAction func closeWW(_ sender: Any) {
self.dismiss(animated: true, completion: {
NotificationCenter.default.post(name: self.back_view, object: nil)
})
}
//现在,在上一个控制器中
override func viewDidLoad() {
NotificationCenter.default.addObserver(self, selector: #selector(popView), name: back_view, object: nil)
}
@objc func popView(){
self.navigationController?.popViewController(animated: true)
}
也许这不是最好的答案,但这对我有用:)