Navigation bar issue in Xcode 5 - ios

I am using navigation controller in my application. Mostly all controllers have navigation bar hidden false except in one controller. When I pop from that controller then navigation bar is shown weird and the bottom space of about navigation bar is left. Also when I do start editing or do some selection or something else the navigation bar becomes normal and the empty space is removed, but it remains till I don't do anything. I am using Xcode 5, and these happens in both iOS 6 and ios 7 not tested in iOS 5. In view Did disappear of that controller I do     
self.navigationController.navigationBar.hidden = FALSE;
[self.navigationController setNavigationBarHidden:NO];
Also in view will appear of the other controller I have written
self.navigationController.navigationBar.hidden = FALSE;
[self.navigationController setNavigationBarHidden:NO];
In both the view auto layout is false as I need to change frame dynamically on different conditions. Please help.

Use below code.
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
Use willAppear/Disappear instead.

In my case i removed that white space by setting background color of the navigation bar view. like
[[[self navigationController] view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]]];

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];
}

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]
}

pushViewController followed by 'back' button sometimes doesn't pop view

I am using pushViewController to push a view in my application. Pressing the back button works about 95% of the time like you would expect. But if I go in and out of the view as fast as possible I run into a condition where the top bar moves as if a pop has occurred, but the view says. In this state, I am left with a back button, (in normal operation I have changed the text of this button to 'cancel'). pressing back will animate the top bar again, and then I am left with no buttons in the top bar, and I'm stuck inside the view.
Do you have any idea what might be going on here? Here are some more details:
The sub view calls these once or twice:
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
also the sub view is extending a BaseViewController. Inside this base controller all of the view methods are overloaded (they just call super). The one that might be interesting is:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self customizeNavigationBar];
}
- (void)customizeNavigationBar
{
[self.navigationController.navigationBar setTintColor:UIColorFromRGB(kNavigationBackgroundColor)];
UIBarButtonItem *backButton_ = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"ID_BUTTON_BACK", #"") style:UIBarButtonItemStyleBordered target:self action:nil];
self.navigationItem.backBarButtonItem = backButton_;
[backButton_ release];
}
Please let me know if you need more code or if I can explain things better.
--- Edit ----
I also am calling Google Analytics in view will appear. I remember this causing other issues in my app:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSError *error;
if (![[GANTracker sharedTracker] trackPageview:#"/app_new_page"
withError:&error]) { }
}
This code is being put in my actual view (not BaseViewController).
I found the problem. The issue was that I was calling setNavigationBarHidden:NO with animated:NO in viewDidLoad to show the nav bar without animation, but using pushViewContoller with animated:YES.
----- originally -----
[self.navigationController pushViewController:controller animated:YES];
and
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
The solution was to remove setNavigationBarHidden from viewDidLoad and move it into viewWillAppear, and to animate it the same way the view was animated. Since my nav bar was appearing instantly, it was possible to press back before the view controller had finished animating (pushing onto the stack), causing all these issues.
----- solution -----
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
Thanks for your help guys!

How to hide the navigation bar from the initial view screen or on a particular view?

In my app i hav 4 views, i want to hide the navigation bar only from my initial view, when i tried using this code
[[self navigationController] setNavigationBarHidden:YES animated:NO]; it hides the navigation bar of other views too., plz help me to fix this issue ,.
thanks
[[self navigationController] setNavigationBarHidden:NO animated:NO];
add above code in -(void)ViewWillAppear function of other views
Instead of adding [[self navigationController] setNavigationBarHidden:NO animated:NO]; to each of the following views (which may be many), you could just add it to - (void)viewWillDisappear in your initial view... That way it will make sure to add it before leaving that view.
Make sure that you hide the navigation bar in - (void)viewWillAppear, so it'll hide it when you return to the initial view.
The best way to do this and shorter in terms of code is:
- (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];
}
On the desired (hidden top bar) view controller.

Resources