Very silly question but i have messed up on it.
My question is, i have two controller. first controller has an UITableview without navigation bar now when i will select the cell it will go to its corresponding controller which has navigation bar.Now when i will return back to first controller navigation bar should not display it should be hidden. How can i solve the problem.it is being bore to me.
[self.navigationController.navigationBar setHidden:YES];
till now i have used it but it is not working.
please give me solution.
Thanks In advance
EDIT: first view controller----> In viewDidLoad and ViewWillAppear i have used [self.navigationController.navigationBar setHidden:YES]; In viewDidLoad and ViewWillAppear of second view controller i have used [self.navigationController.navigationBar setHidden:NO];
**EDIT2:
First view controller -->
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController.navigationBar setHidden:YES];
and in view will appear...
-(void)viewWillAppear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:YES];
Second controller -->
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController.navigationBar setHidden:NO];
In view will appear --->
-(void)viewWillAppear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:NO];
EDIT *ANSWER*
I have just used
[self.navigationController viewWillAppear:YES];
in viewDidLoad of first and second controller.
You have to write [self.navigationController.navigationBar setHidden:YES]; in first controller's viewWillAppear method.
Also try : [self.navigationController setNavigationBarHidden:YES];
-(void)viewWillAppear:(BOOL)animated
{
[self.navigationController.navigationBar setHidden:YES];
}
or please try this
self.navigationController.navigationBarHidden = TRUE;
Related
I have an app where the first screen (the menu for the app) does not need a navigation bar BUT the rest of the app does.
The code I am using works fine in the sense that the navigation bar is not present on the menu screen and is present elsewhere in the app BUT the BIG PROBLEM is that once you go back to the menu the navigation bar appears for about a split second and then disappears.
That is NOT a very smooth transition.
How do I make the transition SMOOTHER so that the navigation bar DOESN'T even appear for a second when I go back to the menu screen?
Here is the code that I am using:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
return self;
}
- (void)viewDidLoad {
[self.navigationController setNavigationBarHidden:YES animated:NO];
[super viewDidLoad];
}
-(void) viewDidAppear: (BOOL)animated {
[[self navigationController] setNavigationBarHidden:YES animated:NO];
[super viewDidAppear:animated];
}
Try like this,
-(void) viewWillAppear: (BOOL)animated {
[super viewWillAppear:animated];
[[self navigationController] setNavigationBarHidden:YES animated:YES];
}
Hope it may helps you...
In your first 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];
}
In your second view controller (not needed, but good practice for code clarity) :
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
set this in the view did disappear in first screen of the app
[[self navigationController] setNavigationBarHidden:NO animated:YES];
and this in viewdiddisappear of the second VC
[self.navigationController setNavigationBarHidden:YES animated:NO];
Instead of hiding and showing the navigation bar, you can update the alpha for the navigation bar. It will animate smoothly during the transition. For the view controller with transparent nav bar, instead of modifying the nav bar, create a navbar (or just the back button and title etc.) manually in the second controller's view. We will then hide the navbar when transitioning from first view controller to the second one.
On your second controller's viewWillDisappear and on your first view controller's viewWillAppear:, set the navigation bar alpha to zero using self.navigationController.navigationBar.alpha = 0;. Since this is in animation block, this will make the navigation bar disappear during the push animation.
Set the alpha back to one in second controller's viewWillAppear and first controller viewWillDisappear.
In my application, i tried to use the function
[self.navigationCotroller presentModalViewController:nextVC animated:YES];
However, when it goes to the next view, the subview fulfill the whole screen(of course it did)
And the question is , how could i add the bar button which lead the view back?
i have tried to use
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:#"back" style:UIBarButtonItemStyleDone target:self action:#selector(Go)];
in function viewdidLoad, but it did not work, there's no bar or even button showed
UINavigationBar *bb = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 44)];
self.NVBar = bb;
[self.view addSubview:bb];
However, i have no idea how to add a barbutton to the new navigationBar ---NVBar
Would you like to give me a solution?
You will need to pop the new view controller in order for the navigation bar to be automatically included.
In the view controller your code from above is in,
//*** Hook up four buttons to these actions and play around with it for a
//*** better sense of what is going on.
//*** JSBViewController is the name of my test class
//*** You should use your ViewController class that you are currently coding so
//*** you can see the difference of pop/push versus present/dismiss inside of a
//*** navigation controller
-(IBAction)push:(id)sender
{
JSBViewController * viewController = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([JSBViewController class])];
[self.navigationController pushViewController:viewController animated:YES];
}
-(IBAction)pop:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
-(IBAction)present:(id)sender
{
JSBViewController * viewController = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([JSBViewController class])];
[self presentViewController:viewController animated:YES completion:nil];
}
-(IBAction)dismiss:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
For the behavior you are looking for, you will need to use the push method
[self.navigationController pushViewController:viewController animated:YES];
If you use [self.navigationController pushViewController:picker animated:YES]; to push your nextVC, then the Nav Bar should stay at the top. Then you can pop back with ` [self.navigationController popViewControllerAnimated:YES];
It's quite unconventional to use a nav bar to go back from a modal view.
`
I'm using the following code to hide my navigationBar in the detailViewController(my second view),
and it works perfectly fine when I tap any of my object from the MasterViewController(my first view).
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
However, when I filter the table list in the masterViewController using searchDisplayController
and tap any object from the result, the navigationBar in the detailView doesn't get hidden...
Do I have to do any extra work to hide the navigationBar if I use the searchDisplayController?
for Debug, I set the break point on the line of setNavigationBarHidden:YES, and even if
I go to the detailViewController via search result, the application hits the line..
you shuold put [self.navigationController setNavigationBarHidden:YES]; in viewWillLayoutSubviews function.like this:
- (void) viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
[self.navigationController setNavigationBarHidden:YES];
}
it works.
You should try this method:
In that controller, where you declared UISearchController *searchController, you should implement two methods (only for example):
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// if you want to hide Navigation Bar when searchController will become active
_searchController.hidesNavigationBarDuringPresentation = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
_searchController.hidesNavigationBarDuringPresentation = NO;
}
The code above may have differences. Main point in hidesNavigationBarDuringPresentation property (iOS 8.0 and later). Try to play with it, and turn to hidesNavigationBarDuringPresentation = NO before pushing a new controller. After this manipulations I took profit: when pushed UIViewController, setter setNavigationBarHidden:YES become working
if you want to hide Navigation bar then, In your MainWindow xib uncheck "Shows Navigation Bar" attributes of Navigation Controller.
This Will hide the Navigation Bar in your Whole Project. If you want to Show Navigation Bar in any Controller set NavigationBar Hidden = NO in ViewDidLoad Method of that Controller.
you should hack search display controller in some way to hide its built in navigationBar.
here is the answer:
https://stackoverflow.com/a/6337037/1348121
This
- (void) viewWillLayoutSubviews
causes layout problems, so i used code below. Works fine for me.
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO];
}
In my iPhone App there are three views, firstView, secondView and thirdView.
now I want to put Back Button in navigation bar in thirdView only which should take me to back secondView only
for that i m writing this code in first view
self.navigationItem.hidesBackButton:NO;
and it shows the back button in both the views secondView and thirdView
what I should do to hide back button in the the secondView?
I think you have to set [self.navigationItem setHidesBackButton:YES] in your secondView.
And set [self.navigationItem setHidesBackButton:NO] in your thirdView.
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationItem.backBarButtonItem=nil;
}
OR
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationItem.hidesBackButton=YES;
}
To hide the back button in the navigation bar
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
self.navigationController.navigationBar.topItem.hidesBackButton = YES;
}
To show the back button in the navigation bar
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
self.navigationController.navigationBar.topItem.hidesBackButton = NO;
}
I have already post this question but this time I post code. So I have a uiviewController, and in the viewDidLoad of this viewController I hide the backButton of the navigationController. After that, I push a new uiviewcontroller, and I set the backbutton to visible in the viewDidLoad, but the backbutton is still hidden...
Implementation of the first uiviewcontroller
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = #"page2page2page2page2page2";
self.navigationItem.hidesBackButton = TRUE;
}
-(IBAction)click
{
page3 *controller = [[page3 alloc] init];
[self.navigationController pushViewController:controller animated:YES];
[page3 release];
}
Implementation of the page 3
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = #"page3";
self.navigationItem.hidesBackButton = FALSE;
}
and the page3 has no backbutton, but the space is created for the button, because the tile "page 3" is on the right and not in the center... all this happen with the ios 4.2
thx
Neither of the above workarounds seemed to work for me. However when the third view was being displayed, i could see the button blink for a moment. So I suspected the problem (bug) has to do with the animation
When change animated to NO on the pushViewController the problem went away
- (IBAction)btnNext:(id)sender {
[[self navigationController] pushViewController:thirdViewController animated:NO];
}
My trick is setting setNavigationBarHidden to YES and immediately NO.
[self.navigationItem setHidesBackButton:NO animated:YES];
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController setNavigationBarHidden:NO];
So as this the backButton not be animated but it's really work and my manager have not notice it ;P
I get the same behaviour and I must say I find it quite strange. I can't say why it doesn't work but as a workaround you can do:
In page2:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.navigationItem setHidesBackButton:YES animated:YES];
}
And in page3:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.navigationItem setHidesBackButton:NO animated:YES];
}
And remove the calls to self.navigationItem.hidesBackButton = ... in both controllers.
Well, I had the same problem running iOS 4.2. The back button would refuse to appear. Upon autoroating to landscape, it then appears. My solution was to do the following - This fixed the problem...or should we say its a workaround ;)
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.hidesBackButton = YES;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.navigationItem.hidesBackButton = NO;
}