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!

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

get syntax error, can anyone help me?

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'. tabBarController.selectedIndex=2; } @end it is a code challenge problem. ask me to set the selected tab as the 3rd one. and said the tabbatcontroller is named "tabBarController". I use both of dot donation and setSelectedIndex. But I always get the syntax error.

1 Answer

Stone Preston
Stone Preston
42,016 Points

you probably need to access the tab bar controller using self. try using

 self.tabBarController.selectedIndex = 2;

Thanks, Stone! Yes, too careless, It keeps complain that u may need self to access the property. But I thought I have already use it. Thanks for the rapid answer!