When you show up the UINavigationController
, presumably in your application's delegate, make the application's delegate also the navigation controller's delegate. Then watch for view controllers being popped and pushed:
AppController.h
#import <UIKit/UIKit.h>
@interface AppController.h : NSObject
<UIApplicationDelegate, UINavigationControllerDelegate>
{
UIWindow *window;
UINavigationController *viewController;
}
/* MARK: Interface Outlets */
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *viewController;
@end
AppController.h
#import "AppController.h"
@implementation AppController.h
/* MARK: Init and Dealloc */
- (void)dealloc {
self.window = nil;
self.viewController = nil;
[super dealloc];
}
/* MARK: Interface Outlets */
@synthesize window, viewController;
/* MARK: Application Delegate */
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
assert(self.window != nil);
assert(self.viewController != nil);
self.viewController.delegate = self;
/* other initialization */
[self.window makeKeyAndVisible];
return YES;
}
/* MRK: Navigation Controller Delegate */
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)vc
animated:(BOOL)animated
{
UIBarButtonItem *myItem = /* initialize */;
navigationController.topViewController.navigationItem.backBarButtonItem = nil;
navigationController.topViewController.navigationItem.backBarButtonItem = myItem;
}
@end
Additionally, you can ignore custom view controllers by checking wether -[NSObject isKindOfClass:]
match for the wanted view controllers.