导航控制器:UINavigationController

    /*

     导航控制器:UINavigationController 继承自UIViewController

     视图控制器:UIViewController

     UINavigationController:管理UIViewController

     UIViewController:管理UIView

     UINavigationController-》UIViewController -》 UIView

     */

    RootViewController * root = [[[RootViewController alloc] init] autorelease];

    UINavigationController * nav = [[[UINavigationController alloc] initWithRootViewController:root] autorelease];

    NSLog(@"nav is %p",nav);

    

//    root.view.backgroundColor = [UIColor grayColor];

    // 给视图控制器设置标题

    root.title = @"Settings";

    // 关联UINavigationControllerUIViewController

    /*

     每一个导航控制器 都有一个栈 维护它的所有UIViewController

     而且这个栈当中必须至少有一个视图控制器做为该栈的基栈

     

     栈:先进后出

     UINavigationControllerUINavigation Bar(320*44) + CustomView(ctl.view) + UIToolbar(默认隐藏)

     UINavigation Bar:backBarButtonItem(上一级ctl) + leftBarButtomItem + title(titleView) + rightBarButtonItem

     */


    // 显示工具栏

//    nav.toolbarHidden = NO;

    // 让导航栏不透明

    nav.navigationBar.translucent = NO;

//    NSLog(@"%f",nav.navigationBar.frame.size.height);


    self.window.rootViewController = nav;

    

    return YES;

}


RootViewController.m

#import "ViewController1.h"

- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view.

//    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

//    label.backgroundColor = [UIColor redColor];

//    [self.view addSubview:label];

//    [label release];

    

    NSLog(@"%p",self.navigationController);

    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myTap)];

    [self.view addGestureRecognizer:tap];

    [tap release];

}


- (void)myTap

{

 // 视图控制器入栈

    ViewController1 * ctl1 = [[ViewController1 alloc] init];

//    ctl1.navigationController nil

//    ctl1.view.backgroundColor = [UIColor greenColor];

    [self.navigationController pushViewController:ctl1 animated:YES];

    NSLog(@"self %p",self.navigationController);

    NSLog(@"ct1 %p",ctl1.navigationController);

    //    ctl1.navigationController 指向真实的物理空间

//    [self presentViewController:ctl1 animated:YES completion:nil];

    [ctl1 release];

}


ViewController1.m

- (void)dealloc

{

    NSLog(@"%@ dealloc",[self class]);

    [super dealloc];

}


- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view.

    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click)];

    [self.view addGestureRecognizer:tap];

    [tap release];

    

    self.view.backgroundColor = [UIColor colorWithRed:arc4random()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1.0];

    // 每次push的视图控制器都会保存在该结构中

    NSLog(@"%@",self.navigationController.viewControllers);

    

    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];

    label.text = [NSString stringWithFormat:@"%d",self.navigationController.viewControllers.count];

    label.center = CGPointMake(160, 230);

    label.textAlignment = NSTextAlignmentCenter;

    label.backgroundColor = [UIColor clearColor];

    [self.view addSubview:label];

    [label release];

}


- (void)click

{

    ViewController1 * ctl1 = [[ViewController1 alloc] init];

    [self.navigationController pushViewController:ctl1 animated:YES];

    // 不要写漏

    [ctl1 release];

}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值