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

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Calcuccino Programmers' Calculator
($2.99)

DataFon(Build Apps on Windows)
(free)

Infinote Pinboard for Todos and Notes
(free)

picplz
(free)

poG
($2.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 07-30-2008, 02:04 PM   #1 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 93
Default how to change the nav bar back button title?

I'm having a problem setting the text that's shown on the back button of a navigation bar.

I know by default the but displays the title property of the previous view controller, but how do I set the text myself?
mellomike is offline   Reply With Quote
Old 07-30-2008, 03:00 PM   #2 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 26
Default

In your main view init:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
iPhoneGuy is offline   Reply With Quote
Old 07-30-2008, 04:54 PM   #3 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 93
Default

hi I just put that code into my view controller's initWithNibName and it's still showing the title property of the last view controller.
mellomike is offline   Reply With Quote
Old 07-31-2008, 08:37 AM   #4 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 93
Default

anyone have a solution for this?
mellomike is offline   Reply With Quote
Old 07-31-2008, 09:53 AM   #5 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 93
Default

Quote:
Originally Posted by iPhoneGuy View Post
In your main view init:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
hey that did work!!! I was adding that code to the wrong view controller. It's supposed to go inside the calling controller, not the one currently on screen.

Thanks for your help
mellomike is offline   Reply With Quote
Old 07-31-2008, 11:45 AM   #6 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 1
Default

Quote:
Originally Posted by iPhoneGuy View Post
In your main view init:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
Unless I´m misunderstanding something you can just use
Code:
self.navigationItem.title =@"Your Title";
Kyle is offline   Reply With Quote
Old 10-27-2008, 08:59 PM   #7 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 167
Default

I know this is a little late, but...

Quote:
Originally Posted by mellomike View Post
It's supposed to go inside the calling controller, not the one currently on screen.
Is there a way to change it from the controller currently being viewed?

I tried the following, but it doesn't work.

Code:
self.navigationItem.backBarButtonItem.title = @"Test";

Last edited by peejavery; 10-27-2008 at 09:29 PM.
peejavery is offline   Reply With Quote
Old 10-28-2008, 01:09 AM   #8 (permalink)
Physician developer
 
StatCoder's Avatar
 
Join Date: Aug 2008
Location: Austin, TX
Posts: 216
Default

I think the principle is that since you might call your current view from a variety of other views, the back button title needs to be determined by the previous view. Someone did mention that they created another toolbar button in the current view that laid on top of the back button and then named it and it seemed to work.
StatCoder is offline   Reply With Quote
Old 10-28-2008, 08:10 AM   #9 (permalink)
Mobile Geek
 
Join Date: Aug 2008
Location: Florida, USA
Posts: 355
Send a message via AIM to rames44 Send a message via Yahoo to rames44
Default

Well, if worst comes to worst, from your top view you could grab the array of view controllers from the navigation controller, go to the one that's "one down" on the stack and fiddle with it.

Alternately, if view controller A pushes view controller B on top of itself, it could, at that point, make the change before doing the push based on which view controller was being pushed.
rames44 is offline   Reply With Quote
Old 10-28-2008, 11:31 AM   #10 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

Any view controller that's been pushed onto a navbar has a parentViewController. So probably a view controller could manipulate the back button title using that property.
PhoneyDeveloper is offline   Reply With Quote
Old 10-28-2008, 03:34 PM   #11 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 167
Default

I solved my problem with the same solution from another thread.

Call function from other view (stupid question)
peejavery is offline   Reply With Quote
Old 08-01-2010, 07:44 PM   #12 (permalink)
Registered Member
 
krye's Avatar
 
Join Date: Jan 2009
Location: NY, USA
Posts: 280
Default

Sweet. That worked for me too, the usual

Code:
 
UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
	temporaryBarButtonItem.title = @"Back";
	self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
	[temporaryBarButtonItem release];
and

Code:
self.navigationItem.backBarButtonItem.title = @"Back";
didn't work
krye 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


» Advertisements
» Stats
Members: 51,375
Threads: 52,830
Posts: 225,478
Top Poster: BrianSlick (3,576)
Welcome to our newest member, darrentousignant
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:31 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0