Popping View Controller causes Bar Button Item to disappear - ios

I have two ViewControllers in my app. The first ViewController (say, ViewControllerOne) has a Bar Button Item that has a slide in TableView (irrelevant to the question). I have disabled the Navigation Bar in the second ViewController (say, ViewControllerTwo) and added a custom view and a Button. I have written the code to pop ViewControllerTwo in thee action of the button. But once it is popped, the BarButton Item in ViewControllerOne disappears.
here is the code I have written in ViewControllerTwo
[self.navigationController setNavigationBarHidden:YES animated:YES];
And
- (IBAction)backCustom:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
Any idea why the Bar Button Item would disappear because of this? I am sure this code is the reason because, When I remove it, it runs fine with the default NavigationBar.But I need a custom one for my project

in your first Viewcontroller add the following line
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}

Related

UINavigationController back button return to FIrstTableViewController

So I was create three UITableViewControllers with UINavigationController. I want a back button on 3rd UITableViewController, what returns my view to first UITableViewController instead of second.
How can I do that? That must be a real backButton, not a image or something else. Will be perfect to do this only with storyboard.
UPDATE
Perhaps I poorly explained what I want.
I don't want use any button with action on it. I just want something like as setting "address" of 1st TableViewController on my default back button. There is any way to do it?
add a button and connect it to following action
- (IBAction)backToFirstView:(UIButton *)sender
{
[self.navigationController popToRootViewControllerAnimated:YES];
(or)
[self.navigationController popToViewController:yourFirstViewControllerObject animated:YES];
}
There are different ways to navigate from DetailViewController to other view controllers.
We will go through the cases one by one.
First of all I would like to clear that if its your default
navigation bar's back button, then it must return to the last most
view controller only which is actually a default behavior of a
navigation controller.
Second, If you would like to go back to the
last most view controller on the tap of a button placed by you, you
should write the following code
[self.navigationController popToViewController:NAME_OF_A_VIEWCONTROLLER animated:YES];
Third, If you would like to go to the first view controller from where you
started, you should write the following code
[self.navigationController popToRootViewControllerAnimated:YES];
Ok, I found a way to resolve my problem. Thanks for your answers guys, they was very helpful.
So for resolve this problem you just need use link what give me Kumar KL upper, and wrote next method in your UITableVIewController
-(void) viewWillDisappear:(BOOL)animated {
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
// Navigation button was pressed. Do some stuff
[self.navigationController popViewControllerAnimated:NO];
}
[super viewWillDisappear:animated];
}
Now you got a backButton what redirect you to your viewController, BUT title of this button is wrong. Let's resolve that unfair.
Create new class CustomSegueцрфе inherited from UIStoryboardSegue with next code in CustomSegue.m :
- (void)perform
{
UIViewController *sourceView = (UIViewController *) self.sourceViewController;
UIViewController *destinationView = (UIViewController *) self.destinationViewController;
[[destinationView navigationItem] setTitle:#"TitleOfYourViewController" ] ;
[sourceView.navigationItem setTitle:#"TitleOfButton"] ;
[sourceView.navigationController pushViewController:destinationView animated:YES];
}
Now you can go to storyboard and connect 2nd ViewController with 3rd with custom segue.
Like you see UINavigationController uses Title of previous ViewController for button title, so you just need change it.

Navigation bar height changing on hide and unhide

In my application I have to show one screen with navigation bar and then by pushing another controller with no navigation bar.
When I come back I again want to show the navigation bar. But, my navigation bar is not visible with complete height.
I set the navigation bar with no translucent, and style opaque.
can you help me anyone.
this will hide and show navigation bar perfectly:
in first view controller implement:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
in pushed view controller:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
Show some code...
or try showing the navigation bar from the view controller you're coming back from just before you tell it to go back... Should avoid the issue. But suspect you're doing something else wrong.
Use this method:
In view controller where you want to hide navigation bar add the below code in viewWillAppear
[navigationController setNavigationBarHidden:YES];
So, if you are in some view controller:
In view controller where you want to show navigation bar add the below code in viewWillAppear
[self.navigationController setNavigationBarHidden:NO];

Storyboard UITableViewController enable toolbar at bottom of screen

I've created a storyboard based UITableViewController which is working and displaying data.
I now need to add a toolbar that will always be at the bottom of the screen. To do this I have added a toolbar button to my storyboard which has it positioned at the bottom of the screen.
I have added the following to my tableviewcontrollers viewWillAppear method
[self.navigationController setToolbarHidden:NO];
As described here
How to add a toolbar to the bottom of a UITableViewController in Storyboards?
However, I still get no toolbar...any ideas?
You want show toolbar in one view controller which placed in some navigation controller.
- (void)viewWillAppear:(BOOL)animated
{
//View will appear
[self.navigationController setToolbarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
//View will disappear
[self.navigationController setToolbarHidden:YES animated:YES];
}

Why is adding a navigation controller making my array disappear?

Currently I have a UIViewController with a couple of buttons that when pressed move to a UITableViewController. Each button loads a specific array of data to the UITableViewController by identifying the segue of the specific button and displaying the corresponding data.
This works fine as is.
However I wish to add an embedded UINavigationController so I can navigate through the UITableViewController and and corresponding views while still being able to 'press back' to the initial UIViewController.
Firstly, where am I meant to put this. I tried over the tableViewController and 2 things happen -
a) If the segues still go to the UITableViewController, there is no navigation displayed.
b) If I move the segues to go to the UINavigationController, none of my arrays show in the tableViewController, but I do have navigation.
Where do I link my segues or where do I embed the UINavigationController so this works?
(I haven't put any code as I don't think this will involve it, but if it does just let me know and I will add).
Not sure if I'm missing something but, it's not working. I want to be able to still utilize the buttons I already have and not use the buttons on the navigation from the UIViewController to the UITableViewController.
For Hiding the Navigation on root
- (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];
}
The ViewController which has 2 buttons can be made as rootViewController to the NavigationController. The NavigationController can be added to the window.
Window -> NavigationController -> UIViewController (as rootView)
Hope this helps.
Select the root view controller->editor->embed in->navigation controller

Wired black space under screen when pop to previous view controller using UINavigationController

I am using UINavigationController to direct some view controllers.In some view controller, I don't want to use UINavigationBar, but in some others i may use. Now I am try to pop one view controller using UINavigationBar to its previous one which hide UINavigationBar. But when poped, there is one wired black space under screen. After you rotate the screen, the space will disappear.
the normal view controller A should be like this:
when press the text button, a view controller B will be pushed, which is as followings:
when click back button on the navigation bar. A will come out.but there is a black space at the bottom.
If rotate the screen, the space will disappear. And also in A's - (void)viewWillAppear:(BOOL)animated method i hide the navigationbar and let the screen autorotate.
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
[self willAnimateRotationToInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation duration:0];
}
whats wrong with this situation? Any help will be appreciated.
I add setNavigationBarHidden: method in the back button action method. it works. If i add this method in viewWillDisappear: method or others, it seems it doesn't work. The navigation bar will have effect on next appear view controller. which means, there will be a black space in the next view controller in the navigation stack.
Finally, i add a action method for the back button and setNavigationBarHidden:YES in the method, which is as follows:
- (void)backBtnClicked:(id)sender
{
[self.navigationController popViewControllerAnimated:NO];
[self.navigationController setNavigationBarHidden:YES];
}

Resources