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


I am building a tabbed bar iPhone app in xcode5 and I am trying to set the middle tab to be the first view loaded!

I am building a tabbed bar iPhone app in xcode5 and I am trying to set the middle tab to be the first view loaded but I can't find anything on how to do it that works or where to put the code, I am a newb at iOS code right now but I have some knowledge of how it works and how to use xcode and the files and Objective-C

1 Answer


self.yourTabBarController.selectedViewController = YourViewController; 

You can put this in the your appDelegate

Thanks for replying, I will try that out. What do I replaced "YourViewController" with?

All my view controllers have the same class "View Controller" so I am trying to select the view by ID.

So in your ViewController you have other views? Then you could put that code in your init method

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

    return self;

Mind sharing your code?

Yes I have multiple views.

My ViewController.h is "http://pastebin.com/XbQB5FUy" and my ViewController.m file is "http://pastebin.com/L2tRqndD"

Okay looking at your code, Im not seeing where you imported other viewControllers. If they are in the appDelegate, then you can use the selectedViewController I mentioned earlier, but you need to set it in your appDelegate, not in this ViewController. OR

Did you mean you wanted to display the different UIWebViews in this ViewController?

Im assuming you wanted to show any one of these based on a condition? `` @property (strong, nonatomic) IBOutlet UIWebView *webViewSchnapp; @property (strong, nonatomic) IBOutlet UIWebView *webViewSell; @property (strong, nonatomic) IBOutlet UIWebView *webViewBuy;

If so then you don't need to make any changes to the tabController. Remember ViewControllers and Views are not the same. The tabBarController holds ViewControllers.

Therefore, in your viewWillAppear method or your init method, you can put some logic to decide which webView to show to the user. Let me know if Im misunderstanding.

There is one View Controller with multiple Views. I will try test on my own a few times.

But what logic should I put in my viewWillAppear method to choose what webView or tabview I want to display?

Im not sure what the logic is for which view you want to show, but in your viewDidAppear you can use view.alpha values to hide the different Webviews and show them when you need to.