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
wasiq aftab
1,994 PointsTableView Controller + Tab bar Controller
What is the way to use multiple buttons on root view controller linked with different tab views in Xcode 4.5?
I have got 4 buttons on the home screen, I want the flow to go as, when I tap on a button1 it should go to tab1 similarly when I tap on button 2 ,tab2 should be open.
I have tried to use >
- (IBAction)button1:(id)sender { self.tabBarController.selectedIndex = 0; } But it is not working properly, kindly give solution or helping links Much appreciated
1 Answer
Ben Jakuben
Treehouse TeacherYour code about setting the selectedIndex seems like the appropriate way to solve this problem. Can you paste in your whole header and implementation files for us to review? What currently happens when you tap on the button?
It may depend on how your tab and navigation controllers are arranged. Which is first? Is the tab bar embedded in the nav controller or vice versa?
wasiq aftab
1,994 Pointswasiq aftab
1,994 Pointsi am trying another approach, i have set up a tabbar controller programmatically, then i added a new class called rootViewController, i want to set it as root and it would contain the four buttons which would point to four different tabs, but its just showing a blank screen even though the rootViewController has a label and it has no error.
this is my AppDelegate.m
please help.
Ben Jakuben
Treehouse TeacherBen Jakuben
Treehouse TeacherNaming a class "rootViewController" is quite confusing - that term refers to the view controller at the root of your current navigation stack. Can you rename it to something more appropriate?
I think your original code was probably close, but this latest code doesn't have enough for me to go on. Can you restart with something simple, like add a tab bar controller in a storyboard and configure the FirstViewController with 4 buttons? Make sure that works. Then add two more tabs. Make sure that works. Then try and get one button working to switch to one of the other tabs. If you do it piece by piece then you can pinpoint smaller errors.