Swift Handle Back按钮NavigationController以推送到另一个ViewController
我目前正在处理这样的流程:首先,在我按下LoginVC上的登录按钮->推到WebViewVC->按导航栏上的后退按钮->推到一个包含WebViewVC的TabbarVC后,我的意思是WebViewVC是TabbarVC的一个选项卡。因此,我想知道如何处理返回按钮,以便按下TabbarVC,而不是返回LoginVC。在此,我将附加我的屏幕流:Swift Handle Back按钮NavigationController以推送到另一个ViewController,swift,uinavigationcontroller,uinavigationbar,pushviewcontroller,backbarbuttonitem,Swift,Uinavigationcontroller,Uinavigationbar,Pushviewcontroller,Backbarbuttonitem,我目前正在处理这样的流程:首先,在我按下LoginVC上的登录按钮->推到WebViewVC->按导航栏上的后退按钮->推到一个包含WebViewVC的TabbarVC后,我的意思是WebViewVC是TabbarVC的一个选项卡。因此,我想知道如何处理返回按钮,以便按下TabbarVC,而不是返回LoginVC。在此,我将附加我的屏幕流: 左上角的是WebViewVC。多谢各位 在webViewVc中添加此代码(不是选项卡栏中的代码)。在ViewDidLoad中调用addBackButton
左上角的是WebViewVC。多谢各位 在webViewVc中添加此代码(不是选项卡栏中的代码)。在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)
}
在webViewVc中添加此代码(不是选项卡栏中的代码)。在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)
}
可能重复的我假设存在混淆,为什么即使它是tabbarcontroller的选项卡,您也要转到saparate webviewVC?可能重复的我假设存在混淆,为什么您要转到saparate webviewVC,即使它是tabbarcontroller的选项卡?