处理后退按钮NavigationController推到另一个ViewController

问题描述:

我目前正在这样的流程上工作:首先,我按下LoginVC上的登录按钮 - >推到WebViewVC - >按导航栏上的后退按钮 - >推到TabbarVC也包含webViewVC,我的意思是webViewVC是TabbarVC的选项卡。所以我想知道如何处理后退按钮以推送到TabbarVC,而不是回到LoginVC。在这里,我会附上我的屏幕流:处理后退按钮NavigationController推到另一个ViewController

enter image description here

顶部左侧是WebViewVC。非常感谢你!

+1

[试图处理“后”在IOS导航按钮动作](的可能的复制http://stackoverflow.com/questions/18824186/trying-to-handle-back-navigation-button-action-in -ios) – Astoria

+0

我假设有一个混淆,你为什么想要分解webviewVC,即使它是tabbarcontroller的选项卡? – dip

将此代码添加到webViewVc(而不是tabBar中的代码)。在ViewDidLoad中调用addBackButton

注意:您需要将图像更改为资产中的图像,并将TabBarVc的名称更改为您拥有的图像。

func addBackButton(_ viewController: UIViewController) 
    { 
     let backButton: UIBarButtonItem = UIBarButtonItem(image: UIImage(named: "Icon_back"), style: .plain, target: self, action: #selector(self.goToTabBar)) 

     self.navigationItem.setLeftBarButton(backButton, animated: true) 
    } 

func goToTabBar() 
    { 
     self.navigationController?.popViewController(animated: true) 
     self.navigationController?.present(TabBarVC(), animated: true, completion: nil) 
    } 
+0

非常感谢,它的工作。 –