Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Self-Destructing Message iPhone App Designing and Starting the App A Storyboard with a Tab Bar Controller

Stuck

This is the code I have:

// Add your code below! The property for MainViewController's // tab bar controller is named 'tabBarController'.

[self.tabBarController setSelectedIndex:2]; 
UITabBarItem *tab = [tabBarItems selectedIndex:2];

}

@end

Word.

1 Answer

[self.tabBarController setSelectedIndex:2];

1.TabBarItems is an array which is holding the information or lets say the name of al the items which will be stored and displayed as tabs. 2.we need to declare a variable of type UITabBarItem which is named as tab.

  1. We have already selected the current tab to be of number 3( ie index[2]) using the [self.tabBarController setSelectedIndex:2]; method ie the current selected item is Index:2 which we need to assign to tab variable. tabBarItems has the list of all the tabs and the current tab is index:2 which can be accessed using tabBarController so that's how we are going to use the line specified below.

    UITabBarItem *tab= tabBarItems [self.tabBarController.selectedIndex] ;

I hope you understand what i am trying to say here.... and it solves your problem...