views:

94

answers:

1

I want to make a back button for a navigation controller with the title "Back" instead of the title of the previous controller. I'm using this code:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] 
               initWithTitle:NSLocalizedString(@"Back", @"Back")
               style:UIBarButtonItemStyleBordered 
              target:nil 
              action:nil];
self.navigationItem.backBarButtonItem = backButton;

I'd like to be able to skip localizing the "Back" string in my app (since I can only localize it in a limited number of languages). If I give my navigation controller no title, the back button will be automatically localized into whatever the language the user has chosen, so the system has translations of "Back" in many languages.

Is there a way to access the localizations that are already present in the system and use them myself? These are things like "Back", "Cancel", "Done" and so on, which show up when creating one of the standard system buttons.

A: 

You can use initWithBarButtonSystemItem:target:action: to create your button and then pass on of the predefined constants:

typedef enum {
   UIBarButtonSystemItemDone,
   UIBarButtonSystemItemCancel,
   UIBarButtonSystemItemEdit,
   UIBarButtonSystemItemSave,
   ...
} UIBarButtonSystemItem;

Unfortunately Apple didn't make the "Back" button available, but at least some of the other buttons you wanted are available as standard items.

Claus Broch