Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-16-2008, 03:24 AM   #1 (permalink)
New Member
 
Join Date: Jun 2008
Posts: 23
satvik_85 is an unknown quantity at this point
Default 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".

How can i do it...

Thank u,
satvik
satvik_85 is offline   Reply With Quote
Old 06-16-2008, 11:59 AM   #2 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 802
scottiphone is on a distinguished road
Default Re: Setting title for left button of navigation bar...

In your view init function:
self.navigationItem.backButtonTitle = @"Back";

Do yourself a favor if you're working with TableViews by downloading TableView_iPhone document on the Apple site (available through documents)

Do a document search for backbutton. Page 40-41 cover this.
scottiphone is offline   Reply With Quote
Old 06-17-2008, 06:29 AM   #3 (permalink)
New Member
 
Join Date: Jun 2008
Posts: 23
satvik_85 is an unknown quantity at this point
Default Re: Setting title for left button of navigation bar...

hi,

Thanks for replying to post.

I've used the self.navigationItem.leftbarButtonItem.title = @"Back" as well as navigationitem.backBarButtonItem.title = @"Back";

But nothing worked out.

I tried in both loadview method and init method of my viewcontroller class.

Thank you.

satvik
satvik_85 is offline   Reply With Quote
Old 06-17-2008, 07:48 AM   #4 (permalink)
Tutorial Author
 
Join Date: May 2008
Posts: 315
myersn024 is an unknown quantity at this point
Default 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?
myersn024 is offline   Reply With Quote
Old 06-17-2008, 11:55 AM   #5 (permalink)
New Member
 
Join Date: Apr 2008
Location: Onomatopoeia, Lugubriousylvania
Posts: 225
bonehead is an unknown quantity at this point
Default Re: Setting title for left button of navigation bar...

Quote:
Originally Posted by satvik_85
I've used the self.navigationItem.leftbarButtonItem.title = @"Back" as well as navigationitem.backBarButtonItem.title = @"Back";

But nothing worked out.
Check your SDK documentation. The API has changed since scott's original post. You now need to set backBarButtonItem.
bonehead is offline   Reply With Quote
Old 06-18-2008, 08:24 AM   #6 (permalink)
New Member
 
Join Date: Jun 2008
Posts: 23
satvik_85 is an unknown quantity at this point
Default 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.

And its working fine...
satvik_85 is offline   Reply With Quote
Old 07-30-2008, 02:59 AM   #7 (permalink)
bvz
New Member
 
Join Date: Jul 2008
Posts: 22
bvz is on a distinguished road
Default

I am also having difficulty with this.

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)

Last edited by bvz; 07-30-2008 at 03:07 AM.
bvz is offline   Reply With Quote
Old 08-02-2008, 08:07 AM   #8 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 4
debug77 is on a distinguished road
Default

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...)
debug77 is offline   Reply With Quote
Old 08-04-2008, 04:41 AM   #9 (permalink)
bvz
New Member
 
Join Date: Jul 2008
Posts: 22
bvz is on a distinguished road
Default

I think I understand what you are getting at... I'll give that a shot tomorrow and post back here what I figure out.

Thanks
bvz is offline   Reply With Quote
Old 08-06-2008, 05:14 PM   #10 (permalink)
bvz
New Member
 
Join Date: Jul 2008
Posts: 22
bvz is on a distinguished road
Default

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.
bvz is offline   Reply With Quote
Old 10-29-2008, 03:55 AM   #11 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 2
ShadoFlameX is on a distinguished road
Default FINALLY got this working

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
ShadoFlameX is offline   Reply With Quote
Old 04-19-2009, 08:35 AM   #12 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 55
iphone.bank is on a distinguished road
Default

Quote:
Originally Posted by ShadoFlameX View Post
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...
iphone.bank is offline   Reply With Quote
Old 04-19-2009, 08:52 AM   #13 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 55
iphone.bank is on a distinguished road
Default

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.

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];

Thanks a lot to all !!
iphone.bank is offline   Reply With Quote
Old 10-20-2009, 09:37 PM   #14 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 16
sirjec is on a distinguished road
Default

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.

EG:

nextController *controller = self.nextController;
self.navigationItem.title = self.relevantObject.name;
[self.navigationController pushViewController:controller animated:YES];


This sets the back button for the controller to whatever I want. Does this help anyone?
sirjec is offline   Reply With Quote
Old 11-03-2009, 12:20 AM   #15 (permalink)
Umesh Jagtap
 
ujagtap's Avatar
 
Join Date: Sep 2009
Location: Pune, India
Posts: 35
ujagtap is on a distinguished road
Default

Quote:
Originally Posted by iphone.bank View Post
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.

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];

Thanks a lot to all !!
Thanks iphone.bank. This works fine and really perfect solution.
ujagtap is offline   Reply With Quote
Old 11-17-2009, 08:57 PM   #16 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Baltimore, MD
Posts: 1
henikv is on a distinguished road
Angry

Quote:
Originally Posted by ujagtap View Post
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
henikv is offline   Reply With Quote
Old 10-01-2010, 03:48 AM   #17 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 1
hamigwa is on a distinguished road
Default

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.

That's all
hamigwa is offline   Reply With Quote
Old 11-05-2010, 06:09 PM   #18 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: PK
Posts: 27
d4devil is on a distinguished road
Thumbs down Question relavant to LeftBarButtonItem

0 down vote


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,,,,

Regards
Sohaib Qazi
d4devil is offline   Reply With Quote
Old 06-18-2011, 02:10 AM   #19 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 12
priyankranka is on a distinguished road
Default Simple Solution

Friends,

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.

It works like charm.

I hope this help some one.

PS: My Money Book for iPhone, iPod touch, and iPad on the iTunes App Store
priyankranka is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
disable the left button of navigation bar. sasikantpradeep iPhone SDK Development 2 09-21-2010 01:42 AM
Adding right button to navigation bar satvik_85 iPhone SDK Development 1 06-16-2008 12:00 PM
Setting Icon for the app..? jashsayani iPhone SDK Development 2 06-13-2008 08:10 AM
left topbutton of uinavigationbar satvik_85 iPhone SDK Development 1 06-09-2008 08:36 PM
Setting the first responder Fastrak iPhone SDK Development 2 05-02-2008 11:12 AM


» Advertisements
» Online Users: 342
3 members and 339 guests
guusleijsten, Kryckter, LEARN2MAKE
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:48 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0