美文网首页
navigationController

navigationController

作者: 晶宝的小花园 | 来源:发表于2017-02-16 11:30 被阅读0次

    // AppDelegate.m:

    #import "AppDelegate.h"
    #import "oneViewController.h"
    
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        
        self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
        
        //创建navigation controller
        UINavigationController*navigation = [[UINavigationController alloc]init];
        
    
        
        
        oneViewController* onevc = [[oneViewController alloc]init];
    
        [navigation pushViewController:onevc animated:YES];
        
        
       /* //创建vc1
        UIViewController*vc1 = [[UIViewController alloc]init];
        vc1.view.backgroundColor = [UIColor redColor];
        
        //将vc1交给navigation管理
        [navigation pushViewController:vc1 animated:YES];
        
        
        
        //创建vc2
        //将vc2交给navigation管理
        
        
        */
        
        
        //将新创建的navigation 赋值给rootViewController
        self.window.rootViewController = navigation;
        
        
        [self.window makeKeyAndVisible];
        
        return YES;
    }
    
    
    - (void)applicationWillResignActive:(UIApplication *)application {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }
    
    
    - (void)applicationDidEnterBackground:(UIApplication *)application {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }
    
    
    - (void)applicationWillEnterForeground:(UIApplication *)application {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }
    
    
    - (void)applicationDidBecomeActive:(UIApplication *)application {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }
    
    
    - (void)applicationWillTerminate:(UIApplication *)application {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }
    
    
    @end
    
    

    (xib)创建 oneViewController继承自UIviewcontroller
    在xib里加button
    // oneViewController.m:

    //
    //  oneViewController.m
    //  navigation
    //
    //  Created by chenvinci on 2017/2/12.
    //  Copyright © 2017年 cuijing. All rights reserved.
    //
    
    #import "oneViewController.h"
    #import "twoViewController.h"
    
    @interface oneViewController ()
    
    @end
    
    @implementation oneViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        self.navigationItem.title = @"red";
        // Do any additional setup after loading the view from its nib.
    }
    - (IBAction)tonext:(id)sender {
        
        twoViewController* vc2 = [[twoViewController alloc]init];
        
        [self.navigationController pushViewController:vc2 animated:YES];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    /*
    #pragma mark - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        // Get the new view controller using [segue destinationViewController].
        // Pass the selected object to the new view controller.
    }
    */
    
    @end
    
    

    twoViewController.m:

    //
    //  twoViewController.m
    //  navigation
    //
    //  Created by chenvinci on 2017/2/12.
    //  Copyright © 2017年 cuijing. All rights reserved.
    //
    
    #import "twoViewController.h"
    
    
    @interface twoViewController ()
    
    @end
    
    @implementation twoViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        self.navigationItem.title = @"purple";
        
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"<返回" style:UIBarButtonItemStylePlain target:self action:@selector(back)];
        self.navigationItem.rightBarButtonItem =  [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];
    }
    
    //返回上个界面
    -(void)back{
        [self.navigationController popViewControllerAnimated:YES];
    }
    
    //
    -(void)add{
        twoViewController* vc2 = [[twoViewController alloc]init];
        
        [self.navigationController pushViewController:vc2 animated:YES];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    - (IBAction)back2home:(id)sender {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
    
    /*
    #pragma mark - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        // Get the new view controller using [segue destinationViewController].
        // Pass the selected object to the new view controller.
    }
    */
    
    @end
    
    

    相关文章

      网友评论

          本文标题:navigationController

          本文链接:https://www.haomeiwen.com/subject/wencwttx.html