Changing text on automatically created button in navigation bar - ios

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.

Related

Navigation Bar Top Item, not showing back bar button, the left is showing when created but it doesnt show the arrow <

The code is in Objective-C and I would like to have the arrow appearing without adding an image as a src.
I've done projects where it appears automatically when changing the controller.
Here I created the left bar button:
navItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:self action:#selector(returnToPreviousScreen)];
This is showing great and working as desired, but it doesnt show the < arrow on the left side of the text.
If I try to create a backbar button it doesnt work at all; doesnt even shows it.
Try setting backBarButtonItem property on navigationItem, but instead of doing it in the view controller that was pushed, do it in the previous view controller. You can set the target and selector to nil, it won't have any effect when set on backBarButtonItem.

ios - Name of the app near Back button after opening it through push-notification

My iOS application now has only two ViewControllers, the main one with the list of cards and the second one with the information about opened card. On the first ViewController there is no name of my application on the Navigation Bar, while on the second View there is only Back button which returns me to the first screen.
My application has push-notification, which opens the second ViewController with Back Button, but if I open it this way, there is a name of my Application near Back button. When I click on it, it returns me to the first ViewController, but this time there is also the name of Application on the top. I don't want to see app name. How can I solve this problem?
I tested it using both iPhone 4 and iPad.
What you can do is to set the navigation bar title on the viewWillAppear method of you main view controller
-(void)viewWillAppear(BOOL)animated {
[super viewWillAppear:animated]
[self.navigationController.navigationItem setTitle:#""]
}
By défaut, the back button text is the precedent view controller title.
So if your 1st view controller has "YourApp" as title, when you will push a new Controller, the back text will be "YourApp"
You can override it easily :
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil]
Try this
Select your ViewController -> Navigation Item -> Show the attributes inspector -> Back button "Back"
Hope this help you

Back Button Different on Different Navigation View Controllers

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];

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!

How do I make the "Add" button on a navigation bar do something?

So I've taken a few years off since my last iPhone programming adventure, and I've apparently forgotten most of what I learned last time. Plus XCode looks totally different, so I'm having to re-learn that as well.
I've used the Storyboard feature to lay out the basic UI of my next project. The main screen is embedded in a Navigation controller, and I have four buttons on the main screen. Pressing any button causes a sub-view to be loaded; I haven't gotten past the sub-views yet. So, in summary, what I have right now is a main/home screen, plus four separate sub-views, each of which is accessed by tapping a button on the main/home screen. This all works peachy so far.
So. On my first sub-view - call it the "People" screen - I have a bar button item with the "Add" function ([+]) on it. What I'm trying to do is get an Action Sheet to appear when the add button is tapped. Unfortunately, no amount of control-dragging from this button to any location in any .h/.m file in my project will produce the little pop-up where I can set up an action/outlet.
What am I doing wrong here?
addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(addItem:)];
self.navigationItem.rightBarButtonItem = addButton;
Then you have to add a void method called "addItem", in which you have to define what do you want the Add button to do(in your case an actionsheet).

Resources