navigationItem backBarButtonItem title - ios

Having a issue with navigationItem backBarButtonItem title on a embedded UIViewController.
Im embedding UIViewControllers in scrollview for pagination, and i want to change the back button title for localization when i push something on the stack of scrollview / pagination controller.
This is the code im trying to do in didSelectRowAtIndexPath:
QueryItemTableViewController *itemView = [self.app.storyboard instantiateViewControllerWithIdentifier:#"QueryItemView"];
self.scrollcontroller.navigationItem.backBarButtonItem.title = #"Test";
[self.scrollcontroller.navigationController pushViewController:itemView animated:YES];
The view QueryItemTableViewController is correctly pushed to the navigationcontroller but the title of the back button is still the title from the previous view.
Any suggestions?

Could you please update the title in ViewDidLoad method of the UIViewController which is being pushed.

Set the navigation title in the first one..
As you push to the next view controller. The back button gets set automatically, with the title you have set for the previous.
Now update the Title of the present view controller in the ViewDidLoad .
So simply these are the steps:
Step 1
always set the title for the current view controller in ViewDidLoad to keep uniformity.
step 2
push to the next UIViewController. Everything gets set automatically.
N.B: You wont get any back button for the first view controller (since it is the root view controller). If you need a back button type button there, simply customise a UIBarButtonItem and use it.

The title of the back button will automatically adjust for localization based on the user’s device language settings.

Related

Swift/XCode 6.4: add back button to navigation controller in navigation bar

In my app I have this storyboard:
and I would like to add a back button from the second table view back to the first. So I inserted a Navigation controller in order to have a navigation bar in the second table view ad I have created a segue with its identifier from the second table view to the first. But then how can I add a back button? I have tried to drag a button from the library into the navigation controller but it won't let me do it...I had already done this but in this moment I can't remember how.
Please can you help me?
In above image you shared you are making your tableview controller as root view controller.You have to kept your navigation controller on root. As you can see in attached image and you don't have to make back button manually as navigation controller has its own default back button.
This example is right how to make storyboard.Try it
self.navigationController?.navigationBar.hidden = false
In setting of UINavigationController set up like on screenshot
If you're using a navigation controller and its default navigation bar, you don't add an explicit back button--the navigation bar does it for you. You can add a UINavigationItem to your view controller, on which you set a title, back button title, etc.

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.

Navigation title not showing on view with tab view controller, but "back" navigation works

I'm relatively new to iOS Objective-C development, and I've come across a problem that I can't find a solution to.
I have a Table View Controller, with two prototype cells on it, which populate fine. This Table View Controller is one of three Tab Views, and the View that sends to the Tab Views has a Navigation Controller. This means that the views within the Tab Views also have a Navigation bar. The bar works fine, in terms of the "back" button working as expected, and the bar being in position. However, (at least on the List View) the Navigation Bar isn't fully recognised - it's title doesn't appear, and the table cells start directly below the status bar, rather than below the navigation bar.
Here's a couple of screenshots showing the problem:
what appears in Xcode (what I expect to happen)
And then on the device, this is what actually appears - the Back button in place and working fine, but no title field, and the table cells start too high.
I've tried adding Navigation Bar's and Navigation Items, and while adding a Navigation Item allows me to put a title on in Xcode, it still doesn't appear on the device in testing. I also tried to add another Navigation Controller just before this view, but that didn't resolve the issue either, and it caused navigation problems further down in the heirachy.
Hope I've been clear enough, please say if I need to post more information - I'm relatively new to Xcode and so not sure what exactly is applicable and what isn't. Thanks!
please try this code, it might fix your table position
// Since in iOS7 the nav bar is translucent by default, so the table view starts at (0,0)
// you can either disable the translucent, which i don't recommend unless you really want to
// or just add 64 pixel on the top of your table view
[self.YOURTABLEVIEW setContentInset:UIEdgeInsetsMake(64, 0, 0, 0)];
and for the title, please try this
self.tabBarController.navigationItem.title =#"YOUT TITLE NAME";
Hope that helps..
Assuming your hierarchy as
NavigationController -> ViewController -> TabBarController -> ViewController1
-> ViewController2
-> ViewController3
If you want to hide navigation item in viewcontroller1, Add the following line
self.navigationController.navigationBarHidden = YES;
If you want to show title in viewcontroller2, Add the following line in
self.navigationController.navigationBarHidden = NO; //add this if you hide navItem viewcontroller1
[self.parentViewController.navigationItem setTitle:#"Title"];
If you want to hide backbutton and show title in viewcontroller3, Add the following line
self.navigationController.navigationBarHidden = NO;
[self.parentViewController.navigationItem setTitle:#"Contacts"];
self.parentViewController.navigationItem.hidesBackButton=YES;
Add this lines to viewdidAppear method instead of ViewdidLoad ,if you have problems inshowing when switching tabs.
I had the same problem, but what I did to create this problem was that my buttons action was connecting to the actual table itself and not the table Controller. I removed the modal action and created a new action to the table controller and it fixed the problem.
Try to click the Navigation Bar from your storyboard or nib.
Then add your title to the property.

Using splitviewcontroller with storyboards?

I have created a splitview controller in a storyboard that has a navigation bar across the top. I also have a master view with a tableview that when selected displays the correct view in the detail view controller.
How can I update the splitview controller's navigation bar title? I know I can access the master's nav bar through "self.navigationItem.rightBarButtonItem" but how do I access the main nav bar from this file?
Thanks
If you have a navigation bar across the top, then you can set the title like this:
self.title = #"this is my title";
If your title is fixed and doesn't change, then just add that line in your viewDidLoad method or where ever you would setup items in your view.
If you are trying to set the title programmatically, then it depends on which view controller you are in when you try to set the title. In the example above, it will set it for the view controller you are in.
If you want to set the opposite view controller navigation bar, you have a couple of ways to choose from depending on when you want to update it.
Generally though you would reference the opposite view controller directly using a delegate or indirectly using the splitViewController.viewControllers array.
it sounds like you already have a reference to the detail view controller. If so and you want to change its title from the master you can do so like this:
[self.detailViewController setTitle:#"New Title"];
hope that helps,
be well

How to programmatically change button title of split view controller?

I've got a split view controller. Thanks.
A UISplitViewController sends splitViewController:willHideViewController:withBarButtonItem:forPopoverController: to its delegate when it hides the master view. You can set the bar button item's title to whatever you want. You can also save the bar button item (in an instance variable for example) and set its title later.

Resources