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 trialElisha Taderera
Courses Plus Student 174 PointsI 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
kerdeseverin
9,688 PointsTry:
self.yourTabBarController.selectedViewController = YourViewController;
You can put this in the your appDelegate
Elisha Taderera
Courses Plus Student 174 PointsElisha Taderera
Courses Plus Student 174 PointsThanks for replying, I will try that out. What do I replaced "YourViewController" with?
Elisha Taderera
Courses Plus Student 174 PointsElisha Taderera
Courses Plus Student 174 PointsAll my view controllers have the same class "View Controller" so I am trying to select the view by ID.
kerdeseverin
9,688 Pointskerdeseverin
9,688 PointsSo in your ViewController you have other views? Then you could put that code in your init method
Mind sharing your code?
Elisha Taderera
Courses Plus Student 174 PointsElisha Taderera
Courses Plus Student 174 PointsYes I have multiple views.
My ViewController.h is "http://pastebin.com/XbQB5FUy" and my ViewController.m file is "http://pastebin.com/L2tRqndD"
kerdeseverin
9,688 Pointskerdeseverin
9,688 PointsOkay 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;
Elisha Taderera
Courses Plus Student 174 PointsElisha Taderera
Courses Plus Student 174 PointsThere 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?
kerdeseverin
9,688 Pointskerdeseverin
9,688 PointsIm 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.