Moaz Khan
Moaz Khan

Reputation: 1352

Swift - open specific tab from button click

I have implemented a UITabBarController and implemented a few tabs. Now I have a button in UITabBarItem from where I want to switch to a specific tab. I have seen answers using navigation controller but in my case, I am not using navigation controller.

NOTE: I have copied this screenshot from the internet so please ignore the navigation bar. I want an answer without using navigation controller.

Upvotes: 2

Views: 7119

Answers (2)

Aditya Srivastava
Aditya Srivastava

Reputation: 2650

Just use this.

self.tabBarController.selectedIndex = indexToWhichYouWantToMove;

tabBarController is the object for your TabBarController

Upvotes: 16

Saurabh Jain
Saurabh Jain

Reputation: 1698

The reference of your tabBarController in your viewController.

Objective C:

[self.tabBarController setSelectedIndex:1];

Swift:

tabBarController?.selectedIndex = 1

Upvotes: 2

Related Questions