[英]Go back to view controller from tab bar controller
I have a viewController.
我有一个viewController。 This view controller goes to a
TabBarViewController
which has two childs. 该视图控制器转到具有两个
TabBarViewController
。 How can I go back from this child(s) to root view controller ? 我怎样才能从这个孩子回到根视图控制器? ( I Want to go back to the first view controller after clicking on UPDATE/CHANGE button )
(我想在单击“更新/更改”按钮后返回第一个视图控制器)
I have tried this but it's not working. 我已经尝试过了,但是没有用。
self.navigationController?.popToRootViewController(animated: true)
你可以试试
self.navigationController?.navigationController?.popToRootViewController(animated: true)
Try this code. 试试这个代码。 it's working for you.
它为您工作。
_ = navigationController?.popToRootViewController(animated: true)
or 要么
_ = navigationController?.popViewController(animated: true)
Try this flow it's working perfectly for me. 试试这个流程,对我来说效果很好。
Set a tag Value for each viewcontroller like below image and use the below code inside the button action. 为每个viewcontroller设置标签值,如下图所示,并在button动作内使用以下代码。
@IBAction func ButtonActin(_ sender: Any)
{
// Button Action from viewcontrollerOne to viewcontrollerZero
tabBarController?.selectedIndex = 0
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.