using this tutorial I set up a custom TabBar. Unfortunately the tutorial won’t describe how to hide the custom TabBar in views you don’t wanna display it.
In my customTabBar.h I defined
- (void) hideAlsoCustomTabBar;
- (void) showCustomTabBarAgain;
which are implemented as
- (void) hideAlsoCustomTabBar {
btn1.hidden = YES;
btn2.hidden = YES;
btn3.hidden = YES;
btn4.hidden = YES;
}
- (void) showCustomTabBarAgain {
btn1.hidden = NO;
btn2.hidden = NO;
btn3.hidden = NO;
btn4.hidden = NO;
}
Calling those inside CustomTabBar.m‘s viewDidAppear works fine and does exactly what I expect them to do. If I try to call those methods from the ViewController where I need to hide the TabBar like this
[customTabs hideAlsoCustomTabBar];
inside the initWithNibName OR viewDidLoad OR viewWillAppear, nothing will happen. I checked with NSLog, the method gets called, but when I read out the BOOL for any buttons .hidden attribute, it returns 0, when it should be 1 (for hidden==YES).
I don’t know what’s wrong with my setup. Is it possible these button’s attributes are private by default as CustomTabBar inherits from UITabBarController and I can’t set them? Or did I make a mistake in the call?
Thanks!
EDIT
The TabBar implementation as it is described in the tutorial
import "CustomTabBar.h"
@implementation CustomTabBar
@synthesize btn1,btn2,btn3,btn4;
- (void) viewDidAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self hideExistingTabBar];
[self addCustomElements];
}
- (void) hideExistingTabBar {
for (UIView *view in self.view.subviews) {
if ([view isKindOfClass:[UITabBar class]]) {
view.hidden = YES;
break;
}
}
}
- (void) addCustomElements {
//Initialise the two images for btnEinleitung, not selected and selected
UIImage *btnImage = [UIImage imageNamed:@"btnEinl.png"];
UIImage *btnImageSelected = [UIImage imageNamed:@"btnEinl_s.png"];
self.btnEinleitung = [UIButton buttonWithType:UIButtonTypeCustom];
btnEinleitung.frame = CGRectMake(0, 430, 86, 50);
[btnEinleitung setBackgroundImage:btnImage forState:UIControlStateNormal];
[btnEinleitung setBackgroundImage:btnImageSelected forState:UIControlStateSelected];
[btnEinleitung setTag:0];
[btnEinleitung setSelected:true];
//set other buttons
btnImage = [UIImage imageNamed:@"btnUbg.png"];
btnImageSelected = [UIImage imageNamed:@"btnUbg_s.png"];
self.btnUebungen = [UIButton buttonWithType:UIButtonTypeCustom];
btnUebungen.frame = CGRectMake(86, 430, 80, 50);
[btnUebungen setBackgroundImage:btnImage forState:UIControlStateNormal];
[btnUebungen setBackgroundImage:btnImageSelected forState:UIControlStateSelected];
[btnUebungen setTag:1];
/* do the same for btn3 and btn4*/
//add custom buttons to view
[self.view addSubview:btn1];
[self.view addSubview:btn2];
[self.view addSubview:btn3];
[self.view addSubview:btn4];
//setup event handlers so the buttonClicked method will respond to the touch up inside event
[btn1 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[btn2 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[btn3 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[btn4 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
}
//set tab to active according to the passed tag number
- (void) selectTab:(int)tabID {
switch (tabID) {
case 0:
[btnEinleitung setSelected:TRUE];
[btnUebungen setSelected:FALSE];
[btnTipps setSelected:FALSE];
[btnBrauchtum setSelected:FALSE];
btnEinleitung.userInteractionEnabled = NO;
btnUebungen.userInteractionEnabled = YES;
btnTipps.userInteractionEnabled = YES;
btnBrauchtum.userInteractionEnabled = YES;
break;
case 1:
[btnEinleitung setSelected:FALSE];
[btnUebungen setSelected:TRUE];
[btnTipps setSelected:FALSE];
[btnBrauchtum setSelected:FALSE];
btnEinleitung.userInteractionEnabled = YES;
btnUebungen.userInteractionEnabled = NO;
btnTipps.userInteractionEnabled = YES;
btnBrauchtum.userInteractionEnabled = YES;
break;
// and so on for 2 and 3
}
self.selectedIndex = tabID;
}
//get the tag of the sender/pressed button, call the function selectTab
- (void) buttonClicked:(id)sender {
int tagNum = [sender tag];
[self selectTab:tagNum];
}
EDIT
As described below, I have 4 Tabs in a Tabbar which was generated with IB, added Navigation Controller with their ViewControllers, made Outlets for those and connected them in IB.
Clicking on the second Tab (e.g. sndMenuVC) opens a view with 4 buttons. Clicking one of these buttons leads to another view (e.g. detailVC) in which I don’t want the TabBar to be displayed. detailVC has it’s own nib.
Opening detailVC happens with the button’s action declared like this
- (IBAction) openFourth:(id)sender{
detailVC *detailView = [[detailVC alloc] initWithNibName:@"detailVC" bundle:nil andSender:kFourthButtonSender];
[self.navigationController pushViewController:detailView animated:YES];
[detailView release];
}
As this is a custom initWithNibName, this is how I implemented it
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andSender: (NSString *)calledByButton{
self.callingButton = calledByButton;
[super initWithNibName:@"detailVC" bundle:nil];
return self;
}
SO I basically just set a global variable “callingButton” according to the transmitted sender and call the “normal” initWithNibName afterwards.
This all works fine.
If I try to call hideAlsoCustomTabBar, and NSLog the value of btn1.hidden it returns 0 when called from detailVC, but returns 1 when called from within CustomTabBar and actually hides the buttons.
I have customTabs as IBOutlet if needed, but don’t know if this is connected correctly to the TabBarController of type CustomTabBar.

Hope this helps to understand me 🙂 If you need any other information, just let me know.
Thanks!
I have written a follow up to my RXCustomTabBar tutorial which should answer your questions. I don’t see any point reproducing it in full here.
Hiding your New Custom UITabBar (RXCustomTabBar follow up)
Let me know if you have any questions,
Oli