I have a problem where a navigation bar suddenly appear after popViewController is called when SearchDisplayCotroller is still active.
I am implementing a simple tableview with searching capability. Above is my storyboard.
On the first view, i've implemented as per below. So, the navigation bar will be always hidden for the first view.
- (void) viewWillAppear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
Button press will push the next table view controller with the below code so that the navigation bar will be visible.
- (void) viewWillAppear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
Everything works fine until i implemented the below code.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.navigationController popViewControllerAnimated:YES];
}
When popViewControllerAnimated:YES while the SearchDisplayController is still active, a weird white navigation bar appears and my viewWillAppear is unable to hide the bar. Is this a bug or is there any way to prevent this bar from appearing?
The gif below may also give you the idea what did happen. Thanks!
Try this
-(void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// To check if searchDisplayController still active
if ([searchDisplayController isActive]) {
[searchDisplayController setActive:NO];
}
}
Try inactivating your UISearchDisplayController by calling setActive:NO animated:NO before you call [self.navigationController popViewControllerAnimated:YES];
https://developer.apple.com/LIBRARY/IOS/documentation/UIKit/Reference/UISearchDisplayController_Class/index.html#//apple_ref/occ/instm/UISearchDisplayController/setActive:animated:
Related
I am using Navigation controller.
In my first screen their is no need of NavigationBar. As this is the Home screen.So I am hiding it using this code:
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES];
}
When I push to new screen I am showing the NavigationBar using this code:
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController NO];
}
The problem is when I come back from other screens to my HomeScreen I am getting black screen in place of navigationBar.
Here is the problem in Image:
White color screen is my ViewController which has navigation bar and BLue one has'n Navigation bar. How can I remove the black part.
Click on the navigation controller and go to attribute inspector and uncheck the show navigation bar option as shown in the screenshot:
try this one
self.navigationItem.hidesBackButton = YES;
There is a better way to do it. All you need to do is create a subclass of UINavigationController class. Set the UINavigationControllerDelegate. Add the following method in the class.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if([viewController isKindOfClass: [SomeClass class]])
[self setNavigationBarHidden: NO];
else
[self setNavigationBarHidden: YES];
}
OR
-(void)viewWillDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
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];
}
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"]]];
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!
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.