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
Sinan the Thinker
7,980 PointsHow to hide back button at UITabBarController
Hi guys,
I am trying to make a variation of the ribbit app with different ussers, and therefore different UITabBarControllers. When I use a segue to connect the UITabBarController, it shows automatically a back button at the UITabBarController.
I tried to solve it with using prepareforsegue, but I wasnt successful.
I also tried to create a custom class for uitabbarcontroller to set it in that class programatically, but I can just create a uitabbar, wherein I cannot set this as a class for the uitabbarcontroller.
if (currentUser){
//the user is logged in. now you need to check the type of the user to determine if you need to segue or not
if ([currentUser[@"type"] isEqualToString:@"garage"]){
NSLog(@"type: %@",currentUser );
[self performSegueWithIdentifier:@"showInboxGarage" sender:self];
// i want that to set setHidesBottomBarWhenPushed:YES to this segue
} else {
NSLog(@"type: %@",currentUser );
[self performSegueWithIdentifier:@"showInboxLeverancier" sender:self ]; // i want that to set setHidesBottomBarWhenPushed:YES to this segue
}
9 Answers
Sinan the Thinker
7,980 Pointsnot solved
Fernando Claussen
9,324 PointsI don't understand, UITabBarControllers doesn't have back buttons.
Aren't you confusing it with the navigation controller?
Sinan the Thinker
7,980 PointsIn the mainstoryboard file there is written Tab Bar Controller. It is the view controller with several tab on it (inbox, friends, etc.)
Fernando Claussen
9,324 PointsYes, but it doesn't give you a back button. What gives you a back button is the Navigation Controller
Robert Bojor
Courses Plus Student 29,439 PointsI believe he wants to hide the bottom bar from a TabBarController actually, if you look at the code example above, written in the comments.
If you want to hide the bottom bar or even a navigation bar you can do so in the destination view controller. I'm using viewWillAppear: to issue these kind of commands - see the example below.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBar.hidden = NO;
self.tabBarController.tabBar.hidden = YES;
[self.navigationController.navigationBar setTranslucent:YES];
[self updateNewsFeed];
}
Sinan the Thinker
7,980 PointsHi,
I want to hide the <- (back) button when arrived at the tabbarcontroller. I will figure it out in combination with above code and navigationItem.hidesbackbutton.
Ive tried
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tabBarController.hidesBackButton = YES;
the result is: property HidesBackButton not found on object of type UITabBarController ... this must be something easy...but how??
Robert Bojor
Courses Plus Student 29,439 PointsThen all you need to do is add
self.tabBarController.tabBar.hidden = YES;
under viewWillAppear on the destination ViewController and you should be fine.
Sinan the Thinker
7,980 Pointsbut where should i add that code? Because I have not created a class for the tabbarcontroller. I am putting this code into inboxviewcontroller (rootviewcontroller) to tabbarcontroller...with no result :/
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showInboxLeverancier"]) {self.tabBarController.tabBar.hidden = YES;}
}
Robert Bojor
Courses Plus Student 29,439 PointsThat code goes inside the viewWillAppear that is on the ViewController your segue points towards.
I'm guessing that segue goes somewhere, well, on the implementation file that handles the destination view controller, under the viewWillAppear method you add that code.
Sinan the Thinker
7,980 PointsHow can I create a UITabBarViewController objective C class ? That code belongs into the viewwillappear of there