6

It's tedious to change it in all view controller

Can I change it globally?

allenwei
  • 4,047
  • 5
  • 23
  • 26
  • Maybe subclass UIViewController, implement it there and make all you ViewControllers of that type. Of course you would still have to touch every existing ViewController at least once. – Andy Friese Mar 21 '12 at 12:36
  • Why would you want to do that? – MrMage Mar 21 '12 at 13:02

1 Answers1

11

What you can use is a category:

UINavigationItem+MyBackButton.h

@interface UINavigationItem (MyBackButton)

@end

UINavigationItem+MyBackButton.m

#import "UINavigationItem+MyBackButton.h"

@implementation UINavigationItem (MyBackButton)

-(UIBarButtonItem*)backBarButtonItem
{
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] 
                                   initWithTitle: @"Back Button Text" 
                                   style: UIBarButtonItemStyleBordered
                                   target: nil action: nil];

    return [backButton autorelease];
}
@end

Add this two files to the project and you are done. To be more efficient ivar and lazy loading should be added here.

A-Live
  • 8,904
  • 2
  • 39
  • 74