从0实现NavigationController

1 AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navController;

@end

2 AppDelegate.m

#import "AppDelegate.h"
#import "RootViewController.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize navController = _navController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    RootViewController *rootViewController = [[RootViewController alloc] init];
    rootViewController.title = @"Root View";
    
    self.navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
    //[self.navController pushViewController:rootViewController animated:YES];
    //[self.window addSubview:self.navController.view];//老的写法
    self.window.rootViewController = self.navController;//self.window.rootViewController是IOS4的新写法
    
    // Override point for customization after application launch.
    //self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

@end

 

你可能感兴趣的:(从0实现NavigationController)