Search code examples
iphoneback-button

iPhone how to get the title for a custom Back-Button


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?


Solution

  • 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?