Setting title for left button of navigation bar...
Hi all,
I need to rename the text on the back button of navigation bar.
For example, i'm in a view say "mainview"(with title "Main"), now am navigating to a different view say "servicesview". the left back button on navigationbar is "Main". but i want to make it back.
this should be for any view ie, even if i'm in any view the previuos back button must be "Back".
Re: Setting title for left button of navigation bar...
This is probably a stupid question, but assuming you're using Interface Builder you have set up the outlet for navigationItem in your services view, right?
Re: Setting title for left button of navigation bar...
Thanks guys,
I'm done with this ...
I have created a new button and assighned it to the leftnavigationbarbutton. And i added slight functionality to make it work like a normal back button.
I am really really trying to figure things out for myself and not keep posting questions here until I am really stuck.
Still, no matter what I try, I cannot get that back button text to change.
Finally, to make it easier to test, I just created the following method and placed it in my UIViewController subclass:
Code:
- (IBAction)TestIt {
self.navigationItem.backBarButtonItem.title = @"Does Not Work";
self.navigationItem.title = @"but This Works";
}
Sure enough, when I call this method, the title of the navigationItem changes, but the back button does not. Does anyone know what I may be doing wrong?
Thanks!
P.S.
Is there some way I can check to see if this is a bug that has already been submitted to Apple by someone else (Assuming it is a bug and not just another misunderstanding by me)
Too me a while to figure this one out, but you actually need to set the Back button title on the 1st view, i.e. the one you want to go back to, rather than on the 2nd view. (If you see what I mean...)
Ok, still have not tried this out yet... (priorities, priorities) but I was going though the "View Controller Programming Guide for iPhone OS" document on Apple's website and I found a diagram on page 27 that confirm's debug77's answer. So, thanks! Not intuitive but once I got it, it makes sense to me.
After looking through these replies I still didn't get a solution, then I found this in an example app:
Code:
// create a custom navigation bar button and set it to always say "Back"
UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
temporaryBarButtonItem.title = @"Back";
self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
[temporaryBarButtonItem release];
After looking through these replies I still didn't get a solution, then I found this in an example app:
Code:
// create a custom navigation bar button and set it to always say "Back"
UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
temporaryBarButtonItem.title = @"Back";
self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
[temporaryBarButtonItem release];
Works like a charm
I tried all the version given in this thread and others.. it is not working.. let me dig more...
Ok, it is working good.
Many others already specified the same in this thread. I just misunderstood.. it seems that we should not add this code to the view where you want to see the back button but to the previous view.. It makes sense. Add the back button to a view controller which is going to be invoked, when you click on the back button. Not to the view controller which shows the back button.
I just came across this thread because I hit the same problem. I use custom TitleViews and this isn't readable by the automatic title of the back buttons.
However,
I managed to get whatever text I wanted displayed in the 'back' button by simply changing the self.navigationItem.title of the previous controller before pushing the new one.
Ok, it is working good.
Many others already specified the same in this thread. I just misunderstood.. it seems that we should not add this code to the view where you want to see the back button but to the previous view.. It makes sense. Add the back button to a view controller which is going to be invoked, when you click on the back button. Not to the view controller which shows the back button.
Thanks iphone.bank. This works fine and really perfect solution.
From Apple's documentation:
For the topmost view controller, the item that is displayed on the left side of the navigation bar is determined using the following rules:
■ If the assign a custom bar button item to the leftBarButtonItem property of the topmost view controller’s navigation item, that item is given the highest preference.
■ If you do not provide a custom bar button item and the navigation item of the view controller one level down on the navigation stack has a valid item in its backBarButtonItem property, the navigation bar displays that item.
■ If a bar button item is not specified by either of the view controllers, a default back button is used and its title is set to the value of the title property of the previous view controller—that is, the view controller one level down on the navigation stack. (If the topmost view controller is the root view controller, no default back button is displayed.)
So you can define the value of the text in either view controller, using the appropriate property. (This took me a couple of hours to figure out
I just edit the *.xib in Interface Builder and change the title of backBarButtonItem easily.
First, open the Inspector and find the Navigation Item in the target View Controller, then click it. In Navigation Item Attributes, you could fill the title in the "Back Button" field. Then a new Bar Button Item will be created in the Navigation Item automatically.
Hi I have 3 view controllers named A,B,C.... I have a function in which i goes from view controller A to B , on B leftbarbuttonItem shows me "A" to go back to viewController A, then i goes from B to C , on C it shows me on leftBarButtonItem "B" to go back to viewController "B". But when I goes from C to B , It is showing me on leftBarButtonItem "C" to go back to viewcontroller "C". Whereas i want the same sequence, means I need A on leftBarButtonitem whenever i come to viewController "B", whether i come from viewController "A" or from "C". I always want to go back from ViewController B to viewController A. Somehow i am manage to change the text on leftBarButton as A in any case. But whenever i comes from C to B, It is showing me now on the top leftBarButton A. But when i clicked it, It will take me to viewController C. Whereas i need to go to viewController A in any case from viewController B. How can i do it? Can someone tell me. I am not getting how to do it.. Looking for a quick and positive response. Any little help will be appreciated greatly in this regards,,,,
When navigating to new controller. In the previous controller's viewDidDisappear make controller title as "Back". This will result in making the Left Navigation bar button title as "Back"
And Make title of the controller set to it's original title in viewWillAppear.