I wanted to add a navigation controller to a view based application . how can we do this both programmatically and using xib file..
If you want to have a navigation controller as the root view for your main window. Then you can do so by using the following code.
@interface yourAppDelegate_iPad : NSObject {
UINavigationController *navigationController;
}
@property (nonatomic, retain) UINavigationController *navigationController;
@end
@implementation yourAppDelegate
@synthesize navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
navigationController = [[UINavigationController alloc] initWithRootViewController:yourRootViewController];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
You can do this by using the xib as follows
- Open the
MainWindow.xib
- Drag and drop a
UINavigationController
to it.- Create and connect the outlets.
- Open attributes for the navigation controller and set the root view.