Hides UINavigationController's UIToolbar when pop - ios

I've two view controller A and B.
A contains a table view and when the user taps on a row, B is pushed.
B has a UIToolbar self.navigationController.toolbarHidden = NO; and the problem is when I pop from B to A: the toolbar remains even on A and I have no idea how to remove.

It's happening because you does not hide toolBar when you pop from B to A viewController.
Use/write following code in B viewController
#pragma mark -
#pragma mark - viewWillDisappear Methods
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.navigationController.toolbarHidden = YES;
}
So, your toolBar hide whenever you pop from B to A viewController.
You Also should try with another option, use same code on viewWillAppear method of A viewController.

Related

iOS - UINavigationController - NavigationBar sliding in together with UIViewController

I have two UIViewControllers, A and B.
A is hiding the UINavigationBar and B is not.
When animating (with the default animation) from A to B, the navigation bar has to become visible. The navigation bar just pops in at some point (viewWillAppear or viewDidAppear) instead of sliding in with the UIViewController B.
When going back from B to A, the navigation bar is smoothly sliding back out.
How can I achieve the desired effect when animating from A to B?
In ViewController B, one has to simply do:
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear: animated];
[self.navigationController setNavigationBarHidden: NO animated: YES];
}
I wasn't aware that this also controls the animation while doing a full view controller transition. I thought it only controls animation the navigation bar out to the top and back in.
You can try the following:
Use a instance variable to do this:
self.navigationController setNavigationBarHidden:hide animated:animated];
_shouldHideStatusBar = hide;
And implement the following function:
- (BOOL)prefersStatusBarHidden{
return _shouldHideStatusBar;
}
The setNavigationBarHidden:animated function will automatically call prefersStatusBarHidden function. If it doesn't you can call it with the following UIViewController's method:
[self setNeedsStatusBarAppearanceUpdate];
And of course you can choose your status bar hiding animation style with:
- (UIStatusBarAnimation) preferredStatusBarUpdateAnimation {
return UIStatusBarAnimationSlide;
}
Let me know if this helps. Good luck!!
(I got this answer here: How to slide in/out statusBar and navigationBar simultaneously?)

Hide the textview coming from UIViewController

I have A and B UIViewController. A controller has button and textview and click this button it goes to B controller. Then I click the B controller I come back to A controller. But when I come back from B controller I need to hide textview from A controller.
B controller:
-(void)A{
[self.navigationController popToRootViewController animated:YES];
}
You are using poptoviewcontroller method so after going back to previous controller the data still persists. So, before navigating to B controller from A controller hide the textview, so that when navigation view pops to main view, the textview will be hidden
Try to use like this...
There are two solution
1.
- (void)viewDidLoad
{
[super viewDidLoad];
textview.hideen = NO;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
textview.hidden = YES;
}
2 . Use a key in NSUserDefaults for status . I mean check it is coming from B Controller or not.
There are many options for this:
Before navigating to the next view hide the textview.
Hide the textview in the viewwilldisappear method.
Use a key with NSUserDefaults and check whether it is coming from B controller.
Declare a variable in appdelegate and change its value in B controller check the value in a controller hide the textview based on result.
You can navigate to another page by declaring a view controller and setting it to naviagation controller before that you can set the properties of that controller.
->write code in controller A
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(hideTextview) name:#“hidetextview” object:nil];
}
- (void) hideTextview{
textview.hidden = YES;
}
->in controller B
(void)viewWillDisappear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] postNotificationName:#"hidetextview" object:nil userInfo:nil];
}
The simplest thing you could do is hide the text view in viewcontroller A before you navigate to view controller B so the code needs to be added in the
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
textview.hidden = YES;
}
OR
- (void)navigateToBController{
VCB *b = [[VCB alloc]init];
[self.navigationController pushviewController:b];
textview.hidden = YES;
}
If you are navigating from A -> B -> C and then in viewcontroller C you navigate to root view controller i.e A then in this case what i would suggest is to maintain a variable in NSUSerDefault which would inform you from which viewcontroller it has popped so that you could show / hide your textview.

ViewWillApear only works once for displaying navigationBar

I'm navigating from a UITableView to a normal ViewController.
I'm displaying the navigationBar like this:
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
The first time I hit a row in the UITableView, the navigationBar shows up, but the second time it remains hidden. This is not expected behavior, since viewWillAppear should work every time the view shows up.
Why is the navigationBar hidden when viewing the view for the second time?
This is because you are hiding navigation bar in viewWillAppear of table view. So it will hidden for other pushed view controllers. So in order to get rid of that you have to un hide navigation bar in view did disappear of table view.So it will work in desired manner.
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.navigationBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.navigationController.navigationBar.hidden = NO;
}

Can i know in viewWillAppear that it was called after navigationController pop (back button)?

Say I have UIViewController A and B.
User navigates from A to B with a push segue.
Than user presses back button and comes to A.
Now viewWillAppear of A is called. Can I know in the code here that I came from back button (navigationController popTo...) and not by another way? And without writing special code in the B view controller.
hm, maybe you can use self.isMovingToParentViewController in viewWillAppear, see docs, if it is NO then it means the current view controller is already on the navigation stack.
I like to do the following in view controller A:
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (_popping) {
_popping = false;
NSLog(#"BECAUSE OF POPPING");
} else {
NSLog(#"APPEARING ANOTHER WAY");
}
//keep stack size updated
_stackSize = self.navigationController.viewControllers.count;
....
}
- (void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
_popping = self.navigationController.viewControllers.count > _stackSize;
....
}
What you are doing is keeping track of whether your view controller (A) is disappearing because a view controller (B) is being pushed or for another reason. Then (if you did not modify the child view controller order) it should accurately tell you if (A) is appearing because of a pop on the navigation controller.
Add a BOOL property to UIViewController A:
#property (nonatomic) BOOL alreadyAppeared;
Then in your viewWillAppear: method, add:
if (!self.alreadyAppeared) {
self.alreadyAppeared = YES;
// Do here the stuff you wanted to do on first appear
}

Alter view when detail view pushed iOS

I have a view with a custom bar at the bottom of the screen. When a collection view cell is pressed, it loads a detail view, and I can go back.
This all works great; however, I have a plus button displayed on the custom bar, and I would like for the plus button to disappear only when the detail view shows up, and then come back when you hit the back button.
So far I have used the delegate method:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
// Your code to update the parent view
}
The problem is this fires when the detail view is loaded and popped as well. Any idea on how to accomplish this? Thanks!
I assume mainView and detailView are viewControllers. In mainView's viewWillAppear method
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//get reference of plus button here
btnPlus.hidden = NO;
}
In detailView's viewWillAppear method
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//get reference of plus button here
btnPlus.hidden = YES;
}

Resources