Reputation: 2960
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?
Upvotes: 1
Views: 621
Reputation: 523534
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?
Upvotes: 3
Reputation: 40991
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
Upvotes: 1