Back button title

Discussion in 'iPhone/iPad Programming' started by sujithkrishnan, Mar 2, 2009.

  1. macrumors 6502

    Joined:
    May 9, 2008
    Location:
    Bangalore
    #1
    Hi all,
    I want to know how to set the back button title of navigation controller.
    I tried doing the following but it didn't work.
    self.navigationItem.backBarButtonItem.title = @"Back";
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    You need to set the title of the navigationItem before you push the new viewController onto the stack. So, something like:
    Code:
    self.navigationItem.title = @"Back";
    [appDelegate.navController pushViewController:nextController animated:YES];
    Then don't forget to restore the title to its original value when you pop back.
     
  3. thread starter macrumors 6502

    Joined:
    May 9, 2008
    Location:
    Bangalore
    #3
    Thanks for the reply.It worked.
     
  4. macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #4
    If you have a specific view controller in your navigation controller that you want to display a back button, I would try this before you push that view:

    [[self navigationItem] setTitle: @"myTitle"];

    UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Back" style: UIBarButtonItemStyleBordered target: nil action: nil];

    [[self navigationItem] setBackBarButtonItem: newBackButton];

    [newBackButton release];

    Place that in the loadview or init method of your new view controller.
     
  5. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Does this technique allow the back button to maintain it's "arrowhead" style?
     
  6. macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #6
    Yes. setBackBarButtonItem takes care of the arrowhead style.

    setBackBarButtonItem also takes care of the target and action, which is why you can just init a button with no (nil) target or action. The method will add those for you.
     

Share This Page