segue adds a navigation to the view - ios

I have added a NavigationBar to View2 with a "Back" item and then I ctrl-dragged from this item to View1 to add a segue (a show segue). Now whenever "Back" is used to navigate to View1, I get a navigation bar (with an item "back") to this view (View1). I only want a navigation bar to View2, not View1. I can always hide View1's NavigationBar programmatically but I am wondering if I am doing something wrong.

You need to hide navigation Bar for View1 inside ViewWillAppear and unhide while going to viewWillDisappear:
View1:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setHidden:true];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController.navigationBar setHidden:false];
}
View2:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setHidden:false];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController.navigationBar setHidden:true];
}
Any one of class function you can use, either view1 functions or view2 functions to hide and unhide navigation bar while switching controller.

Related

Navigation Bar Changes Height

When I push my UIViewController to the screen from my previous controller it animates the change. But when it finishes loading it resizes my navigation bar and the jumpy transition makes it look bad. How can I fix this? All I'm doing is hiding the navigation bar in Controller A in viewWillAppear and showing it in Controller B in viewDidLoad.
Ok solved it. In viewDidLoad of Controller B (the view controller I'm pushing) add the following:
UINavigationBar *navigationBar = self.navigationController.navigationBar;
[navigationBar setBackgroundImage:[UIImage new]
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[navigationBar setShadowImage:[UIImage new]];
Then in your UIViewController's XIB make a height constraint on the navigation bar and set it to 68 (from testing the actual line seems to fall in between 68 and 69). Smooth as silk.
edit: If anyone has any better ideas please add them. I'll have to modify this solution for screen rotation so its not perfect.
You can do all in your controller A like this:
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
}

Hiding a UINavigationBar after hitting back button

I have 3 view controllers and they are all chained together like so:
vc1 -> vc2 -> vc3
In view controller 1 and 2, I have the navigation bar hidden like so:
elf.navigationController.navigationBarHidden = NO;
The third view controller shows the navigation bar and has a back button on the left. When I hit the back button it goes to view controller 2 but the navigation bar is no longer hidden. How do I hide it again?
write this code in viewWillAppear method in viewController1 and viewController2
-(void)viewWillAppear:(BOOL)animated{
self.navigationController.navigationBarHidden = YES;
}
Thanks
Use this simple code in Third view controller
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}

How to hide navigation bar on a particular view controller inside of navigation controller

I have 8 view controllers embedded into 1 navigation controller. I'd like to hide the navigation bar (keeping status bar) on my first view controller. When I've tried to do this this, the navigation bar disappears on all my view controllers.
Try this in the first view controller:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
}

hiding the aView's Navigationbar push bView is OK.but pop Can see the black bars

SDK 6.1, Target 6.1, use storyboard
aView has a a UIButton. I use action segue [push] to the bView
When I click this button push bView is ok
But I pop aView have a back bars, how do I solve this problem?
aView.m
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setHidden:YES];
}
bView.m
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setHidden:NO];
}
I got what is your problem. You are hiding your navigation bar in the viewWillAppear: method of viewA and you are doing it without animation.
Try this
// This will add an animation like slide out. So you may won't like it.
[self.navigationController setNavigationBarHidden:YES animated:YES];
If it is not working, then add this code in bView.m
- (void)viewWillDisappear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:YES animated:NO];
[super viewWillDisappear:animated]
}

navigationController popToRootViewController, the navigation bar shows backButton and son view's title

I'm beginner for iOS dev. In my app, RootView jump to son views: A、B、C、D through buttons (defined in storyboard, push segue). i use some image to be touched so the son views can push to each other, I.E the code in B Controller:
// jump to View C
[self.navigationController pushViewController:CView animated: YES];
the code in C Controller, define backButton clicked to show RootView:
-(void) viewWillDisappear:(BOOL)animated {
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
[self.navigationController popToRootViewControllerAnimated:NO];
}
[super viewWillDisappear:animated];
}
It's perfect to show RootView, but the top shows backButton and title which i defined in B Controller. RootView have an image title. Other view's title was set in storyboard.
What can i do now?
solved, the navigationBar also need to be poped:
-(void) viewWillDisappear:(BOOL)animated {
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
// add this pop:
[self.navigationController.navigationBar popNavigationItemAnimated:NO];
[self.navigationController popToRootViewControllerAnimated:NO];
}
[super viewWillDisappear:animated];
}

Resources