开发者

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

How shou开发者_如何学Cld I go about creating a NavigationController for use in a view-based application?


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.


  • UINavigationController tutorial w/ multiple xibs and data sharing
  • View Controller Programming Guide for iPhone OS


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜