My app flow requires Navigation and TabBar controller. So I decided to use TabBar template. Since my first page is login which do not require TabBar, I used presentModelViewController to show Login screen which have Navigation bar if user Navigate to Forgot password.
LoginView *rootView = [[[LoginView alloc] init] autorelease];
navigationController= [[[UINavigationController alloc] initWithRootViewController:rootView] autorelease];
[tabBarController presentModalViewController:navigationController animated:FALSE];
Ones the user login I dismiss view controller and show TabBar with 5 Tab and Each Tab contain TabaleView. User select any row and navigate to sub view.
The issue is, on sub view I dont need tab bar. (TabBar is needed ONLY on dashboard). If I hide tabBar a white space remain there. Is there any workaround to solve this issue?
On subview write this mehthod:
Subview.m:
(BOOL)hidesBottomBarWhenPushed{
return TRUE;
}
and in Subview.h
(BOOL)hidesBottomBarWhenPushed;
thats it, it has resolved the issue.
Put this method into your subview, where do you want hide the tababr.
Try this one.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
self.hidesBottomBarWhenPushed = YES;
return self;
}
Best of Luck.
You need to use this method when you are pushing the viewController of your subview.
[viewController setHidesBottomBarWhenPushed:YES];
Hope this helps.
Related
I have a Navigation application that has a view controller in it.. I am now trying to load another NavigationController into that ViewController however I am experiencing problems..
I am trying to do it programmatically because I am not sure how to do it in InterfaceBuilder however the new navigation controller displayes weird.. like it thinks there is a infobar above it.. so has a white gap..
As you can see here.
This is all I am doing to get this ^ current look....
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UINavigationController *newNav = [[UINavigationController alloc] init];
[self.view addSubview:newNav.view];
newNav.navigationItem.title=#"Navigation Controller Example";
}
Any help would be greatly appreciated.
As you say,you just have an Navi-based App, so if you want to add another NavigationController in your application ,you should hide the new NavigationController's bar .Following is the code.
[newNav setNavigationBarHidden:YES animated:YES];
I have a button when it pressed, I want it to take me to another view (the "news" view). Within the news view, I want there to be a navigation bar with a back button. I have a navigationcontroller setup throughout my app but I can't seem to get this to work when this button is pressed. It takes me to the view I want but there is no navigation bar and no back button. This is my code that is implemented when the button is pressed.
If anybody know what I am doing wrong, it would be much appreciated.
Thanks
-(IBAction)news
{
newsViewController *view1 = [[newsViewController alloc] initWithNibName:#"newsViewController" bundle:nil];
view1.title=#"news";
[self.navigationController pushViewController:view1 animated:YES];
}
I am not in my mac, so I can not test code, but if it is working and the only issue you got is not show the bar, what you need to is set the bar to be visible:
From apple docs:
The navigation toolbar is hidden by default but you can show it for
your navigation interface by calling the setToolbarHidden:animated:
method of your navigation controller object. If not all of your view
controllers support toolbar items, your delegate object can call this
method to toggle the visibility of the toolbar during subsequent push
and pop operations.
Something like that is supposed to work:
-(IBAction)news {
newsViewController *view1 = [[newsViewController alloc] initWithNibName: #"newsViewController" bundle:nil];
view1.title=#"news";
[self.navigationController pushViewController:view1 animated:YES];
//Add this line!
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
I hope it can help you.
write the below code in page where you want to show navigation controller
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = NO;
}
I have an application that pulls up a login page when it first starts. This login page goes over the application and does not let anyone through until they've logged in. I also have a settings tab on my main application that needs to lead back to this login screen. Right now it displays the login screen with the tab bar over it. Is there a way to get the login view over the tab bar?
I've done something similar by having views transitioning in over the top of my tab bar. I used yourView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; with a 'close' button to let users return to the tab bar screen. I've not done this so it automatically comes in on app fire-up but instead call the view from a button on the screen separate to the tab bar controls. However, I'm sure you'll be able to utilise this somehow to do what you want.
In fact I've actually used this way of calling up views all over my app, each time it covers the tababr and you have to 'close' it to get back to main tabbed navigation you came from.
Try setting below in your viewDidLoad of login screen:
self.tabBarController.hidesBottomBarWhenPushed = YES;
You can do this by using a subclass of UITabBarController, which then performs various checks in viewDidAppear:. The login view is modally presented, as #Maxwell suggested.
// a subclass of UITabBarController
- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self firstLoadChecks];
}
- (void) firstLoadChecks
{
if (!self.hasLogin) {
id login = [[[LoginViewController alloc] initWithDelegate:self autorelease];
id nav = [[[UINavigationController alloc] initWithRootViewController:login] autorelease];
nav.modalPresentationStyle = UIModalPresentationStyleFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:nav animated:YES];
}
}
// from LoginViewControllerDelegate
- (void) didLogin
{
self.hasLogin = YES;
[self dismissModalViewControllerAnimated:YES];
}
// my LoginViewController can be closed without a login
- (void) dismissModalViewControllerAnimated:(BOOL) animated
{
[super dismissModalViewControllerAnimated:animated];
[self firstLoadChecks];
}
I've a problem with something that seems to be very simple.
My app has a view hierarchy consisting in a UITabBarController containing UINavigationControllers. When I navigate from the root to the second level
I set the hidesBottomBarWhenPushed on true so that the tab bar is hidden
On my firstLevelController:
[secondLevelController setHidesBottomBarWhenPushed:YES];
[self.navigationController pushViewController:secondLevelController animated:YES];
After that when I push to the third level, I bring the tab bar again by doing in the secondLevelController:
[self setHidesBottomBarWhenPushed:NO];
[thirdLevelController setHidesBottomBarWhenPushed:NO];
[self.navigationController pushViewController:thirdLevelController animated:YES];
(I know, I didn't like the [self setHidesBottomBarWhenPushed:NO] either, but it didn´t work otherwise...)
So, here is the problem: when I push the back button in the third level and the second view appears, I need to hide the tabbar again but I couldn´t find the way of doing this.
Any help is appreciated
This is what works for me.
[self setHidesBottomBarWhenPushed:NO];
[thirdLevelController setHidesBottomBarWhenPushed:NO];
[self.navigationController pushViewController:thirdLevelController animated:YES];
[self setHidesBottomBarWhenPushed:YES];
The thirdlevelController shows the tabbar and secondLevelController does not show the tabbar when you pop the thirdLevelController.
On your secondViewController, do :
- (BOOL) hidesBottomBarWhenPushed {
return ([self.navigationController.viewControllers lastObject] == self);
}
This way, the tabbar will always be hidden when you are on the secondViewController, and it will appear on the other view controllers
You can hold a bool value to understand if you are coming from a popViewController
and in viewDidAppear you can detect it an hide your tab bar again.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if(backFromThirdView)
[self setHidesBottomBarWhenPushed:YES];
else
[self setHidesBottomBarWhenPushed:YES];
}
I was actually on the same problem. I always tried to hide the tabbar when selecting a row and to disable hiding after returning to the list (a tableview inside a navigationcontroller) so that the user can select the menu again. I set the tabbarcontroller hidden inside the method
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
but when I hided it inside this method, the Tabbar was still hided when returning to my list again. Now I hide the Tabbarcontroller inside the init method of a specific viewcontroller, maybe this works for somebody else too:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
[self setHidesBottomBarWhenPushed:YES];
return self;
}
now when i select a list item and this viewcontroller will be presented the tabbar is hided, after returning to the list it appears again.
You can try this
You declare in the secondLevelController
static BOOL bottomBarShouldHide = YES;
In the viewDidLoad,
if (bottomBarShouldHide) {
[secondLevelController setHidesBottomBarWhenPushed:YES];
bottomBarShouldHide = NO;
}
else {
[secondLevelController setHidesBottomBarWhenPushed:NO];
bottomBarShouldHide = YES;
}
I hope it could help you.
The New York Times iPhone application has a Tab Bar with five tab bar items. When you select the Latest tab, the app shows the title and abstract/summary in a UITableView. When you select an individual story to read, the Tab Bar disappears and is replaced with a header and footer that appears/disappears depending on the state of the app. How does the app "hide" the tab bar?
Thanks!
Implement this piece of code in the class where you want to hide the Tab Bar.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
self.hidesBottomBarWhenPushed = YES;
return self;
}
All the best.
The view controller that is being pushed onto the navigation controller stack has its hidesBottomBarWhenPushed parameter set to yes. The code would look something like this in the table view's -didSelectRowAtIndexPath.
NSDictionary *newsItem = [newsItems objectAtIndex:[indexPath row]];
NewsDetailViewController *controller = [[NewsDetailViewController alloc] init];
[controller setHidesBottomBarWhenPushed:YES];
[controller setNewsItem:newsItem];
[[self navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
Take a look at the documentation for hidesBottomBarWhenPushed.
p.s. You'll probably get more visibility on this question if you add the tag 'iphone' to it.
I have a view that needs to optionally (depending on some other state) show the navigation controller toolbar. This is the solution I used to show & hide the toolbar (with animation) when the view appears & disappears via navigation. It sounds like what you might be after.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Show the nav controller toolbar if needed
if (someBool)
[self.navigationController setToolbarHidden:NO animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// Hide the nav controller toolbar (if visible)
[self.navigationController setToolbarHidden:YES animated:animated];
}