Sunday, June 9, 2013

UINavigationItem leftItemsSupplementBackButton example in Objective C (iOS).


UINavigationItem leftItemsSupplementBackButton

A Boolean value indicating whether the left items are displayed in addition to the back button.

@property BOOL leftItemsSupplementBackButton

Discussion of [UINavigationItem leftItemsSupplementBackButton]
Normally, the presence of custom left bar button items causes the back button to be removed in favor of the custom items. Setting this property to YES causes the items in the leftBarButtonItems or leftBarButtonItem property to be displayed to the right of the back button—that is, they are displayed in addition to, and not instead of, the back button. When set to NO, the items in those properties are displayed instead of the back button. The default value of this property is NO.[UINavigationItem leftItemsSupplementBackButton]

The value in the hidesBackButton property still determines whether the back button is actually displayed.

UINavigationItem leftItemsSupplementBackButton example.
From UINavigationController Class Reference.

UIBarButtonItem *leftBarButtonItem =[[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(logout)];
self.navigationItem.leftBarButtonItem = leftBarButtonItem;
self.navigationItem.leftItemsSupplementBackButton = YES;

Example of [UINavigationItem leftItemsSupplementBackButton].
promptButtonItem = [[UIBarButtonItem alloc] initWithCustomView: viewContainingPrompt];
self.navigationItem.leftBarButtonItem = promptButtonItem;
self.navigationItem.leftItemsSupplementBackButton = YES;

UINavigationItem leftItemsSupplementBackButton example.
Add another button next to the “back” button on the left of a UINavigationBar

As stated by steipete in the comment to the question, this is possible starting from iOS 5. You can use

self.navigationItem.leftItemsSupplementBackButton = YES;
and then you just need to add an UIBarButtonItem as leftButton to get a second button after the back button

UIBarButtonItem *secondButton = [[UIBarButtonItem alloc] initWithTitle:@"Second" style:UIBarButtonItemStylePlain target:self action:@selector(yourAction)];
self.navigationItem.leftBarButtonItem = secondButton;
secondButton = nil;

End of UINavigationItem leftItemsSupplementBackButton example article.