Chisx
Chisx

Reputation: 1986

Complications that may arise from setting UITabBarController's selectedIndex property

Sometimes in my app that I'm developing, I find myself in a position where I just need to navigate back to a specific tab view of my UITabBarController. When I do this I usually just change the tabBarController's selectedIndex and then use presentViewController: on the tabBarController, like so:

UITabBarController * tabControl = [self.storyboard instantiateViewControllerWithIdentifier:@"TabBarControl"];
tabControl.selectedIndex = 1;

[self presentViewController:tabControl animated:YES completion:nil];

Will this cause instance problems? As in.. will doing this simply create another instance of the tab bar tab that I have navigated to, seemingly "reloading" that tab bar view?

Upvotes: 0

Views: 57

Answers (1)

ushika
ushika

Reputation: 1521

As the method name in your code suggests, you will be creating a new view controller object every time you are navigating to a specific tab view. You should only keep a single UITabBarController object in your app, probably in AppDelegate or a singleton object, and use that object for navigation.

Upvotes: 2

Related Questions