Md. Mostafizur Rahman
Md. Mostafizur Rahman

Reputation: 481

Go back to view controller from tab bar controller

enter image description hereI 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

Answers (3)

arunprasath sivasamy
arunprasath sivasamy

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
}

enter image description here

Upvotes: 0

Shehata Gamal
Shehata Gamal

Reputation: 100503

You can try

self.navigationController?.navigationController?.popToRootViewController(animated: true)

Upvotes: 2

Vadlapalli Masthan
Vadlapalli Masthan

Reputation: 176

Try this code. it's working for you.

_ = navigationController?.popToRootViewController(animated: true)

or

_ = navigationController?.popViewController(animated: true)

Upvotes: 0

Related Questions