I've got one view controller that I want to have a top bar, and another that I don't.
They're both in the same navigation controller.
How can I make the first view controller have no top bar, and the second view controller have a top bar?
Edit:
If I use [self.navigationController setNavigationBarHidden:YES]; then there will be a black box where the top bar used to be until the next screen completes it's fly in. How can I avoid this?
Use this property in your first view controller:
[self.navigationController setNavigationBarHidden:NO];
In the second view controller, in the viewWillAppear, put below line,
[self.navigationController setNavigationBarHidden:YES];
In the second view controller, in the viewWillDisappear, put below line,
[self.navigationController setNavigationBarHidden:NO];
Call methods:
[self.navController setNavigationBarHidden:YES];
[self.navController setNavigationBarHidden:NO];
in your ViewWillAppear method for each view you want to hide/show NavController.
Use self.navigationController.navigationBar.hidden = YES; when you want to hide the navigation bar and use self.navigationController.navigationBar.hidden = NO; when you want to unhide it.
You can use this code to hide the navigation bar:
[self.navController setNavigationBarHidden:YES];
and in the next view controller set again:
[self.navController setNavigationBarHidden:NO];
Related
I have a navigation controller (navC) and I have a view controller (ViewC) which is a view pushed from root controller. I have hidden back button for ViewC with code:
[[self navigationItem] setHidesBackButton:YES];
I have pushed tab bar controller (tabbarC) after ViewC . In the view controller associated with the first tab in tabbarC I have tried hiding the back button with the code:
[[[self tabBarController] navigationItem] setHidesBackButton:YES];
But the back button is still visible When i click it; it disappears... can any one help me hiding the back button for all the views in the tabbarC.
In your first view that will appear when you push to your tabbarviewcontroller set this
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.tabBarController.navigationItem.hidesBackButton=YES;
}
In viewDidLoad of ViewC do this:
[self.navigationController.navigationItem setHidesBackButton:YES];
Also tab selected view controller's viewWillAppear method
[self.navigationController.navigationItem setHidesBackButton:YES];
In your view just write this line..it will hide back button .. tested
-(void)viewWillAppear:(BOOL)animated
{
[self.navigationItem setHidesBackButton:YES];
}
How to navigation to previous page!
I add navigation controller to appDelegate so thought out the application i do have navigation controller.
I hidden navigation Bar and added HeaderView on the top.
// Hidden NavigationBar
- (void) viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
Now customize my header bar with UIView! I hidden navigation Bar and added HeaderView on the top.
Now i added BackButton to the header Bar. Now i want to navigation pervious page. Can any one suggest me?
#Thanks In Advance.
if the view is called by a push action, call :
[self.navigationController popViewControllerAnimated:YES];
else if the view is displaying by a modal call :
[self dismissModalViewControllerAnimated:YES];
Use [self.navigationController popviewControllerAnimated :YES];
Use this when the user taps the Back button:
[self popViewControllerAnimated:YES];
#
I have two view named FirstView and Second View. Now I have one button in SecondView. If i click this button then i want to move FirstView. What is the code for it?
I don't want Navigation Bar.
And My button should work as a "Back" Button.
#
You could still use a UINavigationController, but hiding the navigation bar with calling
[self.navigationController setNavigationBarHidden:true animated:false];
in the second view's viewDidLoad method.
Then just show the second view by pushing it on the navigation stack in the first view:
[self.navigationController pushViewController:secondViewController animated:true];
and pop it from the stack when your button is pressed in the second view:
[self.navigationController popViewControllerAnimated:true];
Add SecondView as subview of FirstView. To go back, in the action method of back button, you could remove it from parent view.
In firstView :
[self addSubview:secondView];
In secondView :
- (IBAction)backButtonClicked:(id)sender {
[self removeFromSuperview];
}
When I touch cancel button in the third view, I want to go back to the first view directly. How can I do that?
This is the code.
// this part is in the first view.
SecondController *aSecondController = [[SecondController alloc] init];
UINavigationController *aNaviController = [[UINavigationController alloc] initWithRootViewController:aSecondController];
self.naviController = aNaviController;
[aNaviController release];
[aSecondController release];
[self.view addSubview:naviController.view];
// this part is in the second view.
ThirdController *thirdController = [[ThirdController alloc] initWithStyle:UITableViewStyleGrouped];
[self.navigationController pushViewController:thirdView];
[thirdView release];
// this part is in the third view.
- (void)cancel {
[self.navigationController popViewControllerAnimated:NO]; // this only goes to the second view.
}
popToViewController, popToRootViewController only go to the second view also.
You can use popToRootViewController:animated: method, if your root view controller is the one you're after. You can also use popToViewController:animated: to specify which controller you want to end up with on the top of the navigation stack.
Use UINavigationControllers -popToRootViewControllerAnimated:
- (void)cancel {
[self.navigationController popToRootViewControllerAnimated:NO];
}
And if you ever want to pop to a specific view controller you can use popToViewController:animated: and use the viewControllers property to get the view controller at the correct index.
Set up the navigation controller in your app delegate. Make the first view controller the nav controller's root controller instead of having the first view controller own the nav controller. Then you can use -popToRootViewController:animated: as the other answers have suggested.
I've been wandering how to hide / remove / disable only the main or first navigation bar in the navigation controller so that I could put an image as a whole background screen but I couldn't find any solution.
Did try hide the titleview in viewdidLoad of the main navigation controller but didn't work. Tried using navigationBarHidden but it hides the whole navigation bar for the next stack of controller.
So, I'm not sure how to do this. To give you an example, I would like to have something like this app - The Masters Golf Tournament - http://appshopper.com/sports/the-masters-golf-tournament.
If you look at Screen 1, it doesn't have any nav bar at the top but when you touch any options it will push to a new view controller and have the nav bar appear as in Screen 3,4 and 5.
Hope anyone could help me with this.Thanks a lot!
In most of my applications I have a custom UIViewController class that I derive all other custom controllers from. In some of these, I added a method like navigationBarInitiallyHidden to the base class that other classes can override. The default result depends on the nature of the application.
In the delegate of the navigation controller, when a controller is being shown that implements that method, the delegate hides or shows the navigation controller accordingly. Since I animate the hide or show, I check the current state and do nothing if no change is needed.
You could do something simpler in your delegate method. If the controller being shown is the root controller, hide the navigation bar, otherwise show it if it is hidden.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if ( viewController == rootController ) {
[navigationController setNavigationBarHidden:YES animated:animated];
} else if ( [navigationController isNavigationBarHidden] ) {
[navigationController setNavigationBarHidden:NO animated:animated];
}
}
You can hide the navigation bar:
[self.navigationController setNavigationBarHidden:YES];
and where you want to show the navigation bar again
[self.navigationController setNavigationBarHidden:NO];
hide/disable
self.navigationController.navigationBarHidden = YES;
show/Enable
self.navigationController.navigationBarHidden = NO;
You can hide navigation bar by using bellow code. Below code will hide navigationbar at the time of viewWillAppear.
Objective C
-(void)viewWillAppear:(BOOL)animated
{
[[self navigationController] setNavigationBarHidden:YES animated:NO];
}
Swift
self.navigationController?.setNavigationBarHidden(true, animated: animated)