Reputation: 481
I have a viewController. This view controller goes to a
TabBarViewController
which has two childs. 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)
Upvotes: 0
Views: 1082
Reputation: 228
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.
@IBAction func ButtonActin(_ sender: Any)
{
// Button Action from viewcontrollerOne to viewcontrollerZero
tabBarController?.selectedIndex = 0
}
Upvotes: 0
Reputation: 100503
You can try
self.navigationController?.navigationController?.popToRootViewController(animated: true)
Upvotes: 2
Reputation: 176
Try this code. it's working for you.
_ = navigationController?.popToRootViewController(animated: true)
or
_ = navigationController?.popViewController(animated: true)
Upvotes: 0