I have a UINavigationController in a UITabBarController, and I can't seem to get a pushed viewController's tabBar to hide.
I am using the following code to hide it:
Before it gets pushed:
tpsv.hidesBottomBarWhenPushed = YES;
tpsv.tabBarController.hidesBottomBarWhenPushed = YES;
viewWillAppear:
self.tabBarController.tabBar.hidden = YES;
AppDelegate *del = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[[[del tabController] tabBar]setHidden:YES];
But none of the above work.
If you could tell me how to fix this, that would be great.
You set this before you push the new view controller:
MyViewController *myVC = [[[MyViewController alloc] init] autorelease];
myVC.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:myVC animated:YES];
[EDIT: comment re usage]
Just noticed you say you tried this. Not sure what else you're doing in the context of pushing your VC or configuring it but this does work fine. It's how I do this exact thing in my apps.
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
NSLog(#"%#", view);
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
}
}
[UIView commitAnimations];
}
I've faced the same problem with
myVC.hidesBottomBarWhenPushed = YES;
It does'nt remove the tab bar in subsequent views. May be it's deprecated. You should'nt face this problem with the setHidesBottomBarWhenPushed: command. Try using the following for views:
MyViewController *myVC = [[[MyViewController alloc] init] autorelease];
[myVC setHidesBottomBarWhenPushed:YES];
[self.navigationController pushViewController:myVC animated:YES];
Related
I am adding a tabbarcontroller from a uiview controller. Please check my code:
UITabBarController *tabBarController = [[UITabBarController alloc] init];
NSMutableArray *arrControllers = [[NSMutableArray alloc] init];
for(int i = 0; i<arrTabs.count;i++){
NSArray *arr = [arrTabs objectAtIndex:i];
if([[arr objectAtIndex:0] isEqualToString:#"PICS"]){
picTabViewController *pics = [[picTabViewController alloc] initWithNibName:#"picTabViewController" bundle:nil];
UINavigationController *picsNVC = [[UINavigationController alloc] initWithRootViewController:pics];
picsNVC.tabBarItem.image = [UIImage imageNamed:#"tab-news.png"];
picsNVC.tabBarItem.title = [arr objectAtIndex:1];
[arrControllers addObject:picsNVC];
}
if([[arr objectAtIndex:0] isEqualToString:#"MAP"]){
mapTabViewController *maps = [[mapTabViewController alloc] initWithNibName:#"mapTabViewController" bundle:nil];
UINavigationController *mapsNVC = [[UINavigationController alloc] initWithRootViewController:maps];
mapsNVC.tabBarItem.image = [UIImage imageNamed:#"tab-news.png"];
mapsNVC.tabBarItem.title = [arr objectAtIndex:1];
[arrControllers addObject:mapsNVC];
}
if([[arr objectAtIndex:0] isEqualToString:#"HTML"]){
htmlTabViewController *html = [[htmlTabViewController alloc] initWithNibName:#"htmlTabViewController" bundle:nil];
UINavigationController *htmlNVC = [[UINavigationController alloc] initWithRootViewController:html];
htmlNVC.tabBarItem.image = [UIImage imageNamed:#"tab-news.png"];
htmlNVC.tabBarItem.title = [arr objectAtIndex:1];
[arrControllers addObject:htmlNVC];
}
}
tabBarController.viewControllers = arrControllers;
self.tabBarController.selectedIndex = 0;
[self.view.window addSubview:tabBarController.view];
The tab bar controller is added as desired. But now I want to add a button to go back to previous page, or you can say remove tabbar and its viewcontrollers from the viewcontroller on which it was added. Can someone please suggest me how can I do it?
Please remember that I have added the tabbarcontroller from viewcontroller and not app delegate.
Regards
Pankaj
I've taken one tabbar and alloc-init once, then I'll show & hide on different UIViews.So there is no need to remove & alloc all the time.
Show Tabbar
[self showTabBar:self.tabBarController];
Hide Tabbar
[self hideTabBar:self.tabBarController];
Code for Showing -> It'll automatically appear by setting its 'Y'::
- (void) showTabBar:(UITabBarController *) tabbarcontroller
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
[view setFrame:CGRectMake(view.frame.origin.x, 519, view.frame.size.width, view.frame.size.height)];
}
else if ([[UIScreen mainScreen] bounds].size.height == 480)
{
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
}
}
else
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 519)];
}
else if ([[UIScreen mainScreen] bounds].size.height == 480)
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
}
}
}
[UIView commitAnimations];
}
Code for Hiding -> It'll automatically disappear by setting its 'Y'::
- (void) hideTabBar:(UITabBarController *) tabbarcontroller
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
[view setFrame:CGRectMake(view.frame.origin.x, 568, view.frame.size.width, view.frame.size.height)];
}
else if ([[UIScreen mainScreen] bounds].size.height == 480)
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
}
else
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 568)];
}
else if ([[UIScreen mainScreen] bounds].size.height == 480)
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
}
[UIView commitAnimations];
}
Hopefully, it'll help you if don't want to alloc & release all the time during application.
Thanks.
Just put this method in AppDelegate.m file and call this method when you want to remove tabbarcontroller from superview and set another view as a parentviewController
-(void)setMainView
{
yourViewController *masterViewController = [[[yourViewController alloc] initWithNibName:#"yourViewController" bundle:nil] autorelease];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.navigationController.navigationBar.hidden=YES;
self.window.rootViewController = self.navigationController;
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:kAnimationKey];
}
and call above method with object of AppDelegate class For Ex..
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setMainView];
i hope this helped you..
i want to make tabbarcontroller programatically. The tabBarController is not displayed in the page. can anyone tell that whts going wrong.and can we make more than one tabbarcontroller in an application
ViewController.m
- (void)viewDidLoad
{
report=[[UIViewController alloc]initWithNibName:#"ViewController" bundle:nil];
View1 *template=[[View1 alloc]initWithNibName:#"View1" bundle:nil];
View2 *acc=[[View2 alloc]initWithNibName:#"View2" bundle:nil];
View3 *four=[[View3 alloc]initWithNibName:#"View3" bundle:nil];
View4 *five=[[View4 alloc]initWithNibName:#"View4" bundle:nil];
nav1=[[UINavigationController alloc]initWithRootViewController:report];
nav2=[[UINavigationController alloc]initWithRootViewController:template];
nav3=[[UINavigationController alloc]initWithRootViewController: acc];
nav4=[[UINavigationController alloc]initWithRootViewController:four];
nav5=[[UINavigationController alloc]initWithRootViewController:five];
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:#"Title" image:[UIImage imageNamed:#"singleicon.png"] tag:0];
UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:#"Reports" image:[UIImage imageNamed:#"doubleicon.png"] tag:1];
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:#" New " image:[UIImage imageNamed:#"clockicon.png"] tag:2];
UITabBarItem *item3=[[UITabBarItem alloc]initWithTitle:#"four" image:[UIImage imageNamed:#"dependenticon.png"] tag:3];
UITabBarItem *item4=[[UITabBarItem alloc]initWithTitle:#"five" image:[UIImage imageNamed:#"toolicon.png"] tag:4];
nav1.tabBarItem = item;
nav2.tabBarItem = item1;
nav3.tabBarItem = item2;
nav4.tabBarItem=item3;
nav5.tabBarItem=item4;
//[item1 setBadge:#"25"];
self.tabBarController=[[UITabBarController alloc]init];
[self.tabBarController setViewControllers:[NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nav5,nil]];
self.report = self.tabBarController;
// [self.report makeKeyAndVisible];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
Use below code:
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nav5,nil]];
self.window.rootViewController = self.tabBarController;
UPDATE:
also for Hide and Show the UITabBar then use bellow code ..
just put this methods in AppDelegate.m file and when you want to hide tabbar at that time just create AppDelegate object and call bellow hideTabBar method
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
int height = 480;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x,view.frame.origin.y, 320, 436)];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller {
int height = 436;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)];
}
}
[UIView commitAnimations];
}
put all the coding in the action of the button and push the tabBarController like that:-
[self.navigationController pushViewController:tabBarController animated:YES];
If you want to add UITabBarController programmatically, then you need to add your tabbarcontroller to your ViewController. you need to use this line,
[self.view addSubview:self.tabBarController.view];
You need to add tabBarController in view you have missed the one line
i just did this
[self.navigationController pushViewController:tabBarController animated:YES];
I have Four Tabs in My Project By Default First tab is selected which is Home Class When user navigate to any other class by selecting any tab i have to check that time that if user is loggedin in my application then he will navigate to class which he selected else he move to Login Screen.
if(appDelegate.sessionId==0)
{
Login *objLogin=[[[Login alloc] initWithNibName:#"Login" bundle:nil] autorelease];
[self.navigationController pushViewController:objLogin animated:YES];
}
else
{
CreatePoll *objLogin=[[[CreatePoll alloc] initWithNibName:#"CreatePoll" bundle:nil] autorelease];
[self.navigationController pushViewController:objLogin animated:YES];
}
}
IF i navigate to Login Screen my tab bar gets Hidden and when i debug the code i came to know that Create Poll class is also get called in background i check this link to show tab bar which is hidden but cant get success. Please help me guys i m stucked with this problem from last 3 days.
Cant see my tabbar in Login Screen.Please Help
just write this code in viewWillAppear: method to hide and show the UITabBar
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate.tabBarController.tabBar setHidden:NO];
UPDATE:
post these method in AppDelegate.m file and when you want to show and hide the Tabbar at that time create AppDelegate object and call this method
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
int height = 480;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x,view.frame.origin.y, 320, 436)];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller {
int height = 480;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)];
}
}
[UIView commitAnimations];
}
I have a tabbar controller. I want to hide the tab bar in a view and want to unhide the same tabbar in the next view.The hidding code is working for the first view but in the second view where i am unhiding the tab bar it is not working..
My code:
For Hiding:
[[self navigationController] setHidesBottomBarWhenPushed:YES];
For Unhiding:
[[self navigationController] setHidesBottomBarWhenPushed:NO];
.h
- (void) hideTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration;
- (void) showTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration;
.m
- (void) hideTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration{
[UIView transitionWithView:tabbarcontroller.tabBar duration:duration options: UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
} completion:^(BOOL finished) {
NSLog(#"tabbar hidden");
}];
}
- (void) showTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration{
[UIView transitionWithView:tabbarcontroller.tabBar duration:duration options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {
for(UIView *view in tabbarcontroller.view.subviews)
{
NSLog(#"%#", view);
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
}
}
} completion:^(BOOL finished) {
NSLog(#"tabbar shown");
}];
//u can call like this
//[self hideTabBarOfThisTabbarController:self.tabBarCon withAnimationDuration:3];
//if u want immediately hide/show the tabbar then duration should be 0.0
I start to develop app in tab bar application template..
Here my first page is login page after loagin it go to home page and all navigation will happen..
Here i don't want tab bar only in login page.How to doo this?
Thanks.....
on the first tab, add whatever check you need for whether or not they are logged in, and if not, present a modal view with the login fields.
//some test here to determine state of self.registered
if(self.registered==FALSE){
LoginViewController *login = [[LoginViewController alloc] initWithNibName: #"loginView" bundle: nil];
login.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController presentModalViewController:login animated:YES];
[login release];
}
With this you can hide and how uitabbarcontroller -
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
NSLog(#"%#", view);
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
}
}
[UIView commitAnimations];
}
You can do like this:
In delegate.h declare your views,
UIView *indicatorView;
UIImageView *splashV;
now in delegate.m
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
indicatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashV=[[UIImageView alloc]initWithFrame:CGRectMake(0, 20, 320, 460)];
[splashV setImage:[UIImage imageNamed:#"Default.png"]];
[indicatorView setBackgroundColor:[UIColor clearColor]];
[indicatorView addSubview:splashV];
[self.window addSubview:indicatorView];
}
& on successful login
-(void)SuccessfulLoginDone
{
[window addSubview:[tabBarController view]];
[window makeKeyAndVisible];
}
Hope that would be much better to do this task.