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-18-2008, 06:20 PM   #1 (permalink)
Tutorial Author
 
Join Date: May 2008
Posts: 315
myersn024 is an unknown quantity at this point
Default Changing UIBackBarButtonItem title?

I need to change the UIBackBarButtonItem title, and I've tried everything I can think of from setting the title to calling setNeedsDisplay on the navigation controller but nothing works. FWIW, I used the navigation-based application template that's in Beta 7.
myersn024 is offline   Reply With Quote
Old 06-18-2008, 06:29 PM   #2 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 802
scottiphone is on a distinguished road
Default Re: Changing UIBackBarButtonItem title?

Post a snippet of code in the hopes it'll be more clear to review what you've done.
scottiphone is offline   Reply With Quote
Old 06-18-2008, 07:00 PM   #3 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 26
iPhoneGuy is an unknown quantity at this point
Default Re: Changing UIBackBarButtonItem title?

In the Main Navigation Views :init put in the following code:

Code:
		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 06-18-2008, 08:15 PM   #4 (permalink)
Tutorial Author
 
Join Date: May 2008
Posts: 315
myersn024 is an unknown quantity at this point
Default Re: Changing UIBackBarButtonItem title?

@iPhoneGuy: your code only works if I change it from this
Code:
self.navigationItem.backBarButtonItem = backButton;
to this
Code:
self.navigationItem.leftBarButtonItem = backButton;
However, doing what you've said negates the actual action that it originally had. That, of course, can be fixed by changing the action. However, I know that there has to be a way to do this. I'll describe how my program works before asking any more questions. In my program I have two view controllers, rootViewController and addToListViewController. RootViewController is the primary view and its view is automatically added as a subview to the main window when the program loads. When you tap the right bar button, the app delegate loads the AddToListViewController and pushes its view onto the view controller stack, so the back button that I'm trying to change the text of is one that is automatically generated by the push method. I don't have any problem changing any of the button attributes by setting any of the properties of self.navigationItem. However, from the AddToListViewController's implementation, nothing works with regards to the back button.

I've tried setting the title with self.navigationItem.backBarButtonItem.title as well as calling setNeedsRedisplay on the navigationItem's view after changing the title....so far no luck.
myersn024 is offline   Reply With Quote
Old 06-18-2008, 08:19 PM   #5 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 26
iPhoneGuy is an unknown quantity at this point
Default Re: Changing UIBackBarButtonItem title?

You need to do it in the root view controller not in any of the child views and it should work. If not please post the init of your root view controller.
iPhoneGuy is offline   Reply With Quote
Old 06-18-2008, 08:33 PM   #6 (permalink)
Tutorial Author
 
Join Date: May 2008
Posts: 315
myersn024 is an unknown quantity at this point
Default Re: Changing UIBackBarButtonItem title?

I tried to do it in the RootViewController, but it didn't work. I very well could have been putting the code in the wrong place, though. My RootViewController actually doesn't have an init method since it doesn't house any data. If it were to have an init method it would just be this:
Code:
- (id)init {
    [super init];
    return self;
}
myersn024 is offline   Reply With Quote
Old 06-19-2008, 02:44 PM   #7 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 26
iPhoneGuy is an unknown quantity at this point
Default Re: Changing UIBackBarButtonItem title?

This should work:

Code:
- (id)init
{
	if (self = [super init]) {
		// Initialize your view controller.
		self.title = NSLocalizedString(@"Title", @"AppTitle");

		UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
        self.navigationItem.backBarButtonItem = backButton;
        [backButton release];
		
	}
	return self;
}
iPhoneGuy is offline   Reply With Quote
Old 06-19-2008, 03:03 PM   #8 (permalink)
Tutorial Author
 
Join Date: May 2008
Posts: 315
myersn024 is an unknown quantity at this point
Default Re: Changing UIBackBarButtonItem title?

I worked on this for a while last night, and the best I could do was creating a left bar button item with the title that I wanted and it's selector called popViewController on the navigation controller. It works, but I like the look of the back button better for this particular purpose as opposed to the square buttons. I'll give the code a try this afternoon once I get home and I'll let you know if it works.

Thanks for the help!
myersn024 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
Setting title for left button of navigation bar... satvik_85 iPhone SDK Development 18 06-18-2011 02:10 AM
IB - UIButton title with a code and shadow marius1625 iPhone SDK Development 5 01-19-2009 01:10 PM
Changing values on UISwitch martinn iPhone SDK Development 3 11-05-2008 04:34 PM
Changing ring to vibrate jwpin iPhone SDK Development 2 07-14-2008 12:19 PM
Changing Views viet124 iPhone SDK Development 3 05-13-2008 10:08 AM


» Advertisements
» Online Users: 333
3 members and 330 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:49 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0