Back Button Different on Different Navigation View Controllers - ios

I have searched and can't figure out what is going on.
I have a NavController set up to root on VC1 which has a push segue to VC2. On VC2 the stock back button is just the Arrow Icon (no Arrow Icon with "Back Text).
In a different part of my app I have another Navigation Controller set up to root on VC5 which pushes to VC6. On VC6, the stock back button is the Arrow Icon with the "Back" text).
I am trying to be uniform but I can't figure out how to change these without loading in my own images (which I really don't want to do). I have tried to look for differences between the Navigation View Controllers but can't find how they are different.
Preferably I would just like the Arrow Icon without the "Back" Text.
Anyone experience this?

Another solution: You can control the text on the back button by setting the title of the view controller you came from.
self.title = #"my title";
And this text will appear on the back button of the next view controller you will navigate to. (Unless you defined an image for the back button)
This is not the best solution, (I prefer faviomob's solution using the storyboard, or programmatically), but it can be convenient in some cases.

Look at my picture. When I select any cell in the table view (in root view controller), the second view controller pushed with '111' back button. So, to have empty text there just set it to whitespace.

To set just the back arrow set the left bar Button item of the Navigation bar. Follow this:
//Set the back image. Use ur own image instead of back.png.
UIBarButtonItem* leftBarButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"back.png"]
style:UIBarButtonItemStylePlain
target:self
action:#selector(leftBarButtonPressed)];
[self.navigationItem setLeftBarButtonItem:leftBarButton];

Related

Can't get default UINavigationController back button to work

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.

iOS7 back button reappearing

Been trying to hide the "back" button on my nav bar. The nav bar is on a tab bar controller and when it first loads, the back button is hidden. But when returning from the child nav controller, the back button appears again with the child view controllers title. I've tried self.navigationBar.navigationItem.hidesBackButton = YES; on my tab bar/nav bar controller in viewDidLoad: and viewWillAppear: methods, and also on my child view controller in my custom button segue method. I also tried setting the buttons title to nil using self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"" style:UIBarButtonItemStyleBordered target:nil action:nil]; but that is returning a symbol for the back button instead of "back". And I don't want either. I've checked other threads on here and tried all the solutions I could find. Not having any luck.. any other ideas? Cheers!
Okay, think I found something that works. I'm not sure if it is the best solution but it's simple and it seems to be working. What I did was, I added my own barButton item in place of the Back button and set the tint to Clear color, then I disabled it from the attributes inspector. So what I am left with is an inactive button with a clear title. let me know if anyone has same problem or if there's a better solution!

UIViewController custom back navigation button

Here's my scenario:
I'm using this open source library https://github.com/SlavaBushtruk/APSplitViewController to create a pseudo splitviewcontroller.
Here's what it looks like so far
The APSplitViewController is pushed from another view within a tabbarcontroller.
When I pushed the APSplitViewController it adds an additional navigation bar to the very top of its view, I have hidden that bar because my "sub" views have their own navigation bars.
I would like to add a button to the left of the blue view that would simulate the actual navigation controllers back button (which is currently hidden)
If I can get it to look look like the back arrow that would be great, if not I can live with just a button that says back.
Any help would be appreciated.
=========
Okay I have added a button like so.
self.left.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Test" style:UIBarButtonItemStylePlain target:self action:#selector(backAction)];
Now if I can just get it to look like the back arrow It would be perfect :)
You can get an image that looks like the back button.

Changing text on automatically created button in navigation bar

I've been a lurker for some time on Stackoverflow, and here is my first iOS post.
I am implementing a UINavigationController programmatically and am using it for the default back buttons. The text that is on the back button is defaulted to the name of the title in the previous navigation bar's view, due to the stack.
I wish to change the text on the back button (left bar button) without creating a new UIBarButtonItem, so that I can avoid using a selector and instead use the stack that I have been using. I also wish to avoid creating a new button object, since there is one already inside the NavController.
Example: NavViewA titled A, advances to NavViewB titled B. The left bar button in NavViewB now says 'A', however, I wish it to say "Turtles".
How would I go about doing this?
If I do end up creating a new UIButtonItem and just using that with a selector that pops, will the default button in the NavController deallocate itself, or will it be taking up memory?
Thanks
You can simply do this in viewDidLoad of your NavViewControllerA
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Turtles" style:UIBarButtonItemStyleBordered target:nil action:nil];
It'll still do the pop for you.

ios navigation bar right button item shifts when pushing new view controller

I have a stack of three VCs that are coordinated through a navigation controller and make use of a navigation bar. On this navigation bar, in each VC, I added the same button (a 'Logout' button) as a right bar button item:
UIBarButtonItem *logoutButton =
[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"LogoutButtonTitle", #"")
style:UIBarButtonItemStyleBordered
target:self
action:#selector(logout)];
[categoriesViewController.navigationItem setRightBarButtonItem:logoutButton];
[[self navigationController] pushViewController:categoriesViewController animated:YES];
So each view controller has this logout button in the navigation bar. When I push any of these controllers onto the navigation stack, the new view controllers loads as expected, everything is displayed and functions correctly, but right after the new view controller is displayed (after the animation finishes) the logout button shifts about 3px to the right.
I've tried adding the button before pushing the VC, in the init methods of the VC, in the viewDidLoad and viewDidAppear but still the same behavior. I can't seem to get rid of this shift.
What's strange is that the back button disappears and reappears when pushing the new VC (using the default animation) but the 'Logout' button seems to stay in place and just shift to the right after the animation finishes. Also, the font on the buttons is not the default font but one of the system fonts (Helvetica light), may be related to this.
Any ideas on why this is happening?
I had the same problem. It is because of your rootviewcontroller not being set. Set the main page or the first page where your first navigation bar would be originating as rootviewcontroller. From there [self.navcontroller] pushviewcontroller...].
Try calling
self.navigationItem.rightBarButtonItem = yourUIBarButtonItem;
Also what is your logout button, is it the correct class? Perhaps a little more code?

Resources