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

Dean Laurea
Dean Laurea
17,484 Points

Hello, I can't seem to figure out Challenge Task 2 for "A Storyboard with a Tab Bar Controller". Suggestions?

Here's what I have so far: The last line with "UITabBarItem *tab" is where the answer should be. What I have written seems to be correct, however, it's wrong. Thanks in advance for your help.

#import "MainViewController.h"
#import "UITabBarItem.h"

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSArray *tabBarItems = self.tabBarController.tabBar.items;

    // Add your code below! The property for MainViewController's 
    // tab bar controller is named 'tabBarController'.
       [self.tabBarController setSelectedIndex:2];
       UITabBarItem *tab = [UITabBarItem selectedIndex:tabBarItems];
}

@end
MainViewController.m
#import "MainViewController.h"
#import "UITabBarItem.h"

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSArray *tabBarItems = self.tabBarController.tabBar.items;

    // Add your code below! The property for MainViewController's 
    // tab bar controller is named 'tabBarController'.
       [self.tabBarController setSelectedIndex:2];
       UITabBarItem *tab = [UITabBarItem selectedIndex:tabBarItems];
}

@end

1 Answer

Dean Laurea
Dean Laurea
17,484 Points

Nevermind, found the solution:

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

Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

deanlaurea , I changed your comment to an answer and marked it as best answer because that's what it is, and for future reference, you should do that to your own posts like this! Happy coding!