How do I disable the backbutton in a navigationcontroller?
When I hide the button like so,
self.navigationItem.hidesBackButton = TRUE;
the buttonarea is still tappable.
If you don't need a back button and since part of navigationBar's existence is to have a back button you can simply hide the navBar. I can post the code to that if you want as Im doing that in couple of projects. Otherwise have your "bug" might not be a bug if you are calling it from the wrong place.
After digging i managed to come up with this.
To hide the back button use:
self.navigationItem.hidesBackButton = YES;
To hide the whole navigationBar use:
self.navigationController.navigationBarHidden = YES;
But this will happen without animation, to animate it use this instead:
[self.navigationController setNavigationBarHidden:YES animated:YES];
This will make a sliding animation together with the navigation view. You will need to provide some other means for the person to get back tho.
Related
I am sort of newbie in Three20 world, and I am trying to hide the back/left button in navigation bar.
Below is the method I am calling to hide it:
[[TTNavigator navigator].topViewController.navigationController.navigationItem setLeftBarButtonItem:nil animated:YES];
[[TTNavigator navigator].topViewController.navigationController.navigationItem setHidesBackButton:YES animated:YES];
Apparently, both the methods doesn't hide the back button. What I am here trying to do is, push the viewcontroller, and when the new controller arrives it doesn't show the back button, yet I had another button there which pop's the view.
I have also tried different routes as:
[VC.navigationController.navigationItem setHidesBackButton:Yes];
The funny part is I am about to set the Title though as:
[VC.navigationItem setTitle:#"Options"];
Any help here will be really appreciated. Thanks.
Try here: Crappy iOS APIs – UINavigationController
Notice that Rafael does this in the new controller, not in the controller which does the push.
self.navigationItem.hidesBackButton = YES;
It works for me.
Dave
I have explicitly set the navigation bar's back button to be hidden by the following method -
[[self navigationItem] setHidesBackButton:YES]
This works fine when I enter this view from a view (which is flip-able, it's a map view). The back button does not appear if I enter the view without flipping the previous view (the map view). However, if I enter this view after flipping the map view, a back button appears. And this button does not function at all on tapping it.
I have tried setLeftBarItem:nil method, but even then it appears (and doesn't function)!
Anyone have a solution to this really odd problem?
You need this
self.navigationItem.hidesBackButton = TRUE;
OR
[self.navigationItem setHidesBackButton: YES animated: YES];
I am having back button and edit button on my navigation bar like below
After clicking on the Edit button, I have
My question : how can I disable click on back button when I am in edit mode so that user can not go back previous screen until he or she is done.....
What I am trying is
self.navigationItem.backBarButtonItem.enabled = NO;
but the back button is still clickable
PS : The way I add back button to navigation bar is
self.navigationItem.hidesBackButton = NO;
I can hide back button but I dont want that option...
Please advice me on this issue. Any comments are welcomed here.
The best solution would be to end edit mode when you are leaving the screen, maybe displaying a confirmation alert first (UIAlertView with two buttons "Ok" and "Cancel").
However, to answer the question - you would have to create a UIButton with the same appearance as a back button (using images). Create a UIBarButtonItem with this button as its custom view and use it in leftBarButtonItem (note that backBarButtonItem cannot have custom views).
Then you would be able to set enabled to NO on that custom view.
EDIT: I was wrong. UIBarButtonItem has enabled property. The problem with disabling the back button was there probably because you were disabling backBarButtonItem on the wrong navigationItem. The back button is always defined by the previous controller in the stack.
If the button is blocked maybe you should hide it. Because in my point of view having a unresponsive button is not good for the user.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[UIView animateWithDuration:0.35f animations:^{
self.navigationItem.hidesBackButton = editing;
}];
}
self.navigationItem.backBarButtonItem.enabled = NO;
Where you put the above code. place the above code in edit button's IBAction method.
I'm writing my first iPhone app and I am trying to figure out how to have a MasterView and DetailsView like in the example. However, instead of using a TableView, I want to use a button on the MasterView to go to the SignUpView. I want the MasterView to NOT have a navigation bar but the SignUpView needs to have one.
I have tried putting a NavigationController into the MasterView using the interface builder. This doesn't seem to do anything at all ... I.e. I make the following call:
[self.navigationController pushViewController:signUpViewController animated:YES];
And nothing happens. The SignUpView is never shown.
So then I declared a NavigationController in the AppDelegate. The above call in the same function that it was in before (button handler, button is in MasterView) works now! It takes me to the SignUpViewController.
however, the issue is, when I press back on the navigation bar in the sign up view, the navigation bar shows up again in the MasterView. I tried to set
self.navigationController.navigationBarHidden = YES;
in viewDidLoad and viewDidAppear, but that causes a black bar to appear in the transition from SignUpView to MasterView.
I tried to not set it in one of the two, and that causes the animation to go smoothly, but the navigation bar shows up in the MasterView.
I feel like this should be pretty simple to do ... but I'm at my wits end trying to figure this out. Some help would be really appreciated!
Thanks.
Probably not the answer to your question, but just a small suggestion. In the many apps that I have come across, a sign-up/sign-in view is generally displayed as a modal view (on top of your master view) with a 'cross' in the top-right corner to dismiss it. Probably it results in a better user experience.
Also, did you try self.navigationController.navigationBarHidden = YES; in the MasterView's viewWillAppear ?
HTH,
Akshay
I had this problem too, until I discovered setNavigationBarHidden. You will probably want to use these in viewWillAppear/viewWillDisappear or viewDidAppear/viewDidDisappear. You don't want to call this in viewDidLoad because that is only called once when the view is initialized, not every time it appears.
To hide:
[self.navigationController setNavigationBarHidden:YES animated:YES];
To show:
[self.navigationController setNavigationBarHidden:NO animated:YES];
I want to make a really simple iphone app: one screen with a single button... when the button is tapped a new screen appears. That's it. No animations, nothing,
I've tried endlessly to make the NavBar sample project do this... and it works but only if I use a UINavigationController with a table that I can tap etc. I've tried all the skeleton projects in XCode too.
I thought I was done when I did this:
[[self navigationController] presentModalViewController:myViewController animated:YES];
But I couldn't do it without the UINavigationController. I just want a simple example.
Thanks so much!
One way you could do this is to create a new UIView and then when the button is pressed add that new UIVIew as a subview, therefore making it what you see.
If you make the new view its own subclass of UIView you would do something like this.
LoginView *login = [[LoginView alloc] initWithFrame: rect];
[mainView addSubview: login];
[self presentModalViewController:myViewController animated:NO];
Will pop up a new view, no animations, nothing. To get rid of it, inside myViewController:
[self dismissModalViewControllerAnimated:NO];
Though I reccomend you use the nice sliding animations (change NO to YES.) And yes, you can stack them up. I think this is better than creating a new UIView, but I may be wrong.
The correct way to do this is set up your project with a UINavigationController. In your root view controller, add your button in the view controllers's view. Then in viewDidLoad, register for UIControlEventTouchUpInside events from you button. Then, in your event callback, call:
[self.navigationController pushViewController:[[[SecondViewControllerClass alloc] initWithNib:nibName bundle:nil] autorelease]];
What kdbdallas suggested will work, but you won't get the nice sliding effects, nor will the navigation bar automatically change and provide your users with a back button.