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 PointstabBar Controller
i have created a single application and then created 2 tabs programmatically, then i have created 2 buttons tab 1 and tab 2 here is the code of .m file
- (IBAction)tab1:(id)sender {
self.tabBarController.selectedIndex=0;
}
- (IBAction)tab2:(id)sender {
self.tabBarController.selectedIndex=1;
}
here is the code of my appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.tabBarController = [[UITabBarController alloc] init];
UIViewController *viewController1 = [[firstViewController alloc] init];
UIViewController *viewController2 = [[secondViewController alloc] init];
self.tabBarController.viewControllers=[NSArray arrayWithObjects:viewController1,viewController2, nil];
//self.window.rootViewController = self.tabBarController;
self.window.backgroundColor = [UIColor whiteColor];
return YES;
}
apparently there is no error in this code, if i set the tabbarcontroller as root it shows the tabs but when i want the viewcontroller to be root and buttons pointing to the tabs it doesnt work.
3 Answers
Amit Bijlani
Treehouse Guest TeacherIt's doing exactly what it's supposed to be doing. The whole point of the UITabBarController is to dynamically create and display tabs based on the viewControllers property.
wasiq aftab
1,994 PointsAmit can you please tell me any snippit code how i can use it. to achive what i want
Amit Bijlani
Treehouse Guest TeacherWhat are you trying to achieve? It's not clear from your post above.
wasiq aftab
1,994 Pointsi have got 2 buttons on the home screen, i want to link multiple buttons with corresponding tabs, when user press button 1, tab 1 should open, when user press button 2 tab 2 should open.
i tried to achieve this using sagues. i created a single view application and used a tab bar controller in storyboard and then i tried to connect each button with different tab node,
i want to know which approach would be most appropriate ? and whats missing ?
if you can provide me with a link to similar example it would be a big help Thanks.
Amit Bijlani
Treehouse Guest TeacherSorry, can you share your project. I'm having a hard time imagining why you would have a button link to a tab. Linking a button a tab seems counter intuitive.
wasiq aftab
1,994 PointsHI
Sorry for my Bad Communication. what i am trying to do .
- Main Screen which have pattles like windows 8
- if some one click on any pattle it will take it to another page/ screen
- and on the screen i have the tab view related to that view.
Difficulty:
i have made the home screen with pattles. now i dont know how i open the next scene on clicking a pattle.
can you please tell me how i can do that.
Amit Bijlani
Treehouse Guest TeacherYou need a navigation controller. Once you have a navigation controller then you can push other controllers.
wasiq aftab
1,994 PointsThanks alot i will try in that way.
wasiq aftab
1,994 Pointsany recommended link which i will study
ralphmannuni
3,022 PointsHey Amit - Again, this is an extra credit example but there is no solution posted anywhere. Futher, Wasiq asked for help 10 months ago and you still didn't reply. Why create extra credit if you guys can't support it?
-R
Amit Bijlani
Treehouse Guest TeacherWasiq mentioned above that he was trying to create a Windows 8 like interface. We don't have any iOS extra credit that asks you to do that. We offer Extra Credit assignments so you can challenge yourself and take your knowledge further. You are not required to do them. The goal is take what you have learned and apply that knowledge. We feel it wouldn't help you to learn if we simply provided you with the answer. As a developer you are constantly in unchartered waters and figuring out solutions is what we do and have to get used to. Google and Stack Overflow are sometimes your best friends.
Finally, the forums are here so students can help each other. We try to help as much as we can but we get flooded with support and it's difficult to answer every question. We rely on our moderators and other students to help each other. You also want to avoid replying to really old threads because those students may no longer be around to respond. If you post a new thread asking for help then I doubt you will not get an answer.