Reputation: 1
I'm a bit new to XCode, so I'm not exactly sure what I did wrong. So thank you in advance to anyone who is willing to help me out :)
I have 2+ view controllers imbedded in a tab bar controller, and each vc is imbedded in a navigation controller, and I want to use a button in a vc to switch to another vc in a different tab. Actually, I was able to do this in a past project: I created an IBAction function that switches to a different tab when a button is pressed. Below is what my code looked like (and it worked with no problems at all)
@IBAction func ButtonPressed(_ sender: UIButton) {
self.tabBarController?.selectedIndex = 1
}
However, it's not working anymore, and I don't know if I did anything differently. Is there a way around this? (Or maybe why this might not be working anymore?)
If that description was a bit confusing, I included a screenshot of what I'm trying to do.
Upvotes: 0
Views: 206
Reputation: 1553
if you're in a navigation controller you might need to do this:
self.navigationController?.tabBarController?.selectedIndex = 1
Upvotes: 1