Make the back button say… back.

Monday 8 February 2010, 8:59AM

A lot of the time, you’re making an iPhone app and you realize that the back button ends up saying “Money spent shopping.” which is both ugly and space-consuming (leaving the title of the page pushed to the right).

Because of this, I have a handy-dandy little code snippet I use every single day:

UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@”Back”, @”Back”) style:UIBarButtonItemStyleBordered target:nil action:nil];

self.navigationItem.backBarButtonItem = backBarButtonItem;

[backBarButtonItem release];

  • Shaps
    Hmm this doesn't appear to be working for me. I'm putting it inside the viewDidLoad method correct?
  • I take it back, was putting it in the wrong UITableViewController. FAIL! I'm officially a newbie! HAHAHA!
    Thanks for the great tips, really helpful.
  • slavingia
    yup
  • Jeff
    I'm new at this, but why is @"Back" repeated twice when initializing with title?
  • slavingia
    That's so I can easily localize the Back button when needed.

    You can use @"Back" Instead of NSLocalizedString(...) if you're not
    going to worry about other languages.
  • Jeff
    Thank you.
  • rybek
    As I commented in the previous post, for example such code:)

    Those are some useful pieces of code, that many iPhoneBeginnerProgrammers (including me) will welcome:)

    Thanks!
  • I dub thee the king of snippets!
blog comments powered by Disqus