sudhakar
sudhakar

Reputation: 51

How can I create a NavigationController in a view-based application?

How should I go about creating a NavigationController for use in a view-based application?

Upvotes: 0

Views: 4730

Answers (3)

Splendid
Splendid

Reputation: 1061

in delegate.h

@class test24ViewController;

@interface test24AppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    test24ViewController *viewController;
    UINavigationController *nav;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet test24ViewController *viewController;
@property (nonatomic, retain) IBOutlet UINavigationController *nav;

in delegate.m

@synthesize nav;

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    nav=[[UINavigationController alloc]init];
        [nav pushViewController:viewController animated:YES];
    // Override point for customization after application launch.


    [self.window addSubview:nav.view];

    [self.window makeKeyAndVisible];

    return YES;
}

Upvotes: 1

Warrior
Warrior

Reputation: 39384

Put this code

In delegate .h class

      MyViewController *viewController;

In delegate .m class

 - (void)applicationDidFinishLaunching:(UIApplication *)application {    

UINavigationController *nvcontrol =[[UINavigationController alloc] initWithRootViewController:viewController];

[window addSubview:nvcontrol.view];

[window makeKeyAndVisible];

}

Here "MyViewController" should be replaced by your viewcontroller.

All The Best.

Upvotes: 2

Related Questions