I have a UIViewController with a navigation bar i dropped in in storyboards. Then I dragged in a UIBarButtonItem which is rectangular.
I want that button to look like a navigation bar's back button
I was suggested to do this:
self.navBar.topItem.backBarButtonItem = self.button;
After properly creating the properties and connecting them to the outlet. I did but the button still looks like the Done Rectangular button. How can I change it?
Those buttons are created automatically when you do a push segue.
For your particular problem, you can call perform [self dismissModalViewControllerAnimated:YES] in the case of modal segues, or [self.navigationController popViewControllerAnimated:YES]; for dismissing custom push segues.
Anyway, I don't know any method to change the button style to the "left arrow", other than selecting a background image with your particular "button".
Related
I have implemented a right item button in the navigation bar. I use the storyboard, no code. But now the back button is not displayed. What's the good way to show it again without boilerplate code ?
Thank you!
You can not see the back button on the rootViewController of the NavigationController
NavigationController automatically add the back button once you push some other ViewController to it.
It will display if you have not hides it explicitly.
If you have drag and drop the BarButtonItem as shown in the attached image, Just run the code and back button will automatically get added if it was not your RootViewController.
If it is RootViewController as displayed in images, try to push some ViewController on it, you will get the back button added.
If you add the left bar button item from Interface Builder, you will not get the back button displayed. Then you have to do it manually
I have a View Controller that has a UINavigationBar in it and I want to show the back button in the nav bar. The reason I am using a View Controller instead of a Navigation Controller is because of a custom animation I am using to switch between views. The back button will be used to start the back animation from the second view.
in any event is there any way I can force show the back button in the UIViewController with the Nav bar in it without creating an icon to use in a UIBarButtonItem
Are you animating actual views, or are they ViewControllers? Animating between viewControllers is perfectly doable using a navigation controller and writing a custom segue. Then there's no trouble of adding a custom back button.
The only disadvantage using a custom segue is that the animation on the navigationBar is gone, resulting in a sudden 'change' of title and appearance of the back button.
Anyway, you could add your own button to the navigationBar using the following code:
yourNavigationBar.topItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:self action:#selector(backButtonPressed)];
Don't forget to implement the backButtonPressed method.
It doesn't include the typical 'back' arrow, but you can solve this by adding an image to the button, or just by creating a custom view and include that in the navBar.
First, I've read almost all of the questions and answers on the web and SO about navigation bar/back button/title/navigation item etc. I have a navigation controller and view controllers. Nothing fancy. Whatever I do, I can't display a back button when I push a new view controller. Neither via storyboard push segues nor programmatically pushing. My view controller and navigation bar displays correctly, when I tap where where the back button should be, it does work, it pops the view controller, however, it's not displayed.
Before you say, I'll list what I've done:
I've got the navigation controller's Shows Navigation Bar set to yes.
I've set a title to my root view controller inside the navigation controller on storyboard.
I've set a back button title to my root view controller inside the navigation controller on storyboard.
I don't have any custom code involving navigation bar/navigation item/left bar button/right bar button/hides back button/back button item.
I've set a title for my navigation controller.
Whatever I do, my back button doesn't get displayed. When I debug, it's set to nil. I've tried instantiating one but it didn't help either. What am I missing?
Firstly check that the controller you are pushing from and to has a navigation item in the viewer you can set title, back button and prompt for. I have found that depending on how storyboard has created the controller it may or may not have one you can see in the view tree. Setting the back button does not seem to work unless you can actually see one in both controllers in storyboard.
Secondly, and something I only realized recently, is that you set the title for the back button in the controller you are pushing "from" and not in the controller that will be showing when the back button is showing.
e.g. If you have controller A and controller B and you are pushing to B from A: you have to set the label for the back button in the navigationItem of controller A, not in the navigationItem of controller B. You may already know this, but its confusing.
define a property in .h
#property (strong, nonatomic) UIBarButtonItem *backButton;
in viewDidLoad in .m
self.backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"backButton.png"] style:UIBarButtonItemStylePlain target:self action:#selector(backButtonPressed)];
self.navigationItem.backBarButtonItem = self.backButton;
and add the method
-(void) backButtonPressed {
[self.navigationController popViewControllerAnimated:YES];
}
oh misread... you don t want a custom button, just the normal one? maybe there is a UIBarButtonSystemItem for back ?? take this instead of a custom image...
checked tintcolor? maybe it s set to clearcolor ??
It was something much simpler. Actually, everything was acting correctly. After some investigation ([[UIWindow keyWindow] recursiveDescription]) I've realized that it was just me who was faulty to set the storyboard's global tint color to the same color with navigation bar. I've explicitly set the tint to white and now the text is seen.
I know that a push segue automatically adds a back button so that the presentee can return to the presenter on click. What I want is for the back button to be available on the first UIViewController of the NavigationController (basically the only view controller in the chain that does not have a back button). How do I force add the back button?
I cannot simply add a custom image because I want the exact same chevron that comes with the iOS back button.
The easiest (yet hackish) way to achieve this is probably adding a dummy view controller in the stack before the actual first one, so you will get a proper back button. Use dummy's backBarButtonItem to customize the button title if you need, and -viewWillAppear: to respond to the button being tapped.
What I want is for the back button to be available on the first UIViewController .... How do I force add the back button
This whole thinking and logic is wrong. This is not how iOS UINavigationControllers work. You have a starting page (mainViewController) in a UINavigationControllers and from there you "move on" to something else. But you always come back to the main view controller. Just think about it, if you put a back button on the main view controller, where will the user go back to?
If you have a situation like this.
SomeViewController --> UINavigationController --> MainViewController
Once user is on SomeViewController and you take him to MainViewController which is part of UINavigationController then back button makes sense.
Just a FYI - you can easily drag and drop a UIBarButtonItem to any UINavigationController in Xcode and call it "Back". You will have to then connect that back button to another view controller.
Maybe it doesn't make sense but why can't you add a custom image? If all you want is "Back" chevron, can't you take a screenshot of this button and then put this image on your custom UIBarButtonItem?
I have an app in which there is a ViewController and once a button is pressed it goes to DetailViewController. In ViewController I have hidden the navigation bar to have more room to display an image while in DetailViewController it is necessary.
When I hit the back button in DetailViewController it goes back, however since it has a navigation bar and ViewController doesn't the animated segue looks bad. I was wondering, is there a way to make the default back button (that comes when embedded into navigation controller) give you a non animated segue?
Thanks
try using [[self navigationController] setNavigationBarHidden:{YES,NO} animated:{YES,NO}]; in view{Will,Did}{Dis}appear instead of setting everything up via Xcode UI controls
You can get good results WITH animation using them too.
If you really want to remove the whole animation, though: Prevent the animation when clicking "Back" button in a navigation bar?