views:

201

answers:

2

Heyho, I'm building a custom green back button which is being created in the "viewDidAppear:" method.

I don't have any problems with the "getting-it-into-the-Navigationbar" or with "popping-the-current-View", but my Problem is:

How do I get the title of the previous controller, so I can set it as Lable for the custom Back Button? And is there a way to know if there even is any?

+1  A: 

This is handled for you automatically. Just set the title of each view, and the UINavigationController takes care of the back button labels for you

Ben Scheirman
this doesn't work with custom-View back buttons, or does it?
Infinite
ah now I see. You want to set it like this:http://pessoal.org/blog/2009/02/03/iphone-sdk-customizing-back-button-title/
Ben Scheirman
+2  A: 

The title of the back button is always the title of the 2nd top view controller.

Thus you can use (after ensuring there are ≥2 view controllers):

NSArray* viewCtrlers = self.navigationController.viewControllers;
UIViewController* prevCtrler = [viewCtrlers objectAtIndex:[viewCtrlers count]-2];
return prevCtrler.title;

If you're going for a green button, why not simply set the nav bar's tint to green?

KennyTM
because we want barbuttons with a different color, than the navigationbar ;)
Infinite
works great so far ;)
Infinite