// [nav pushViewController:c2 animated:YES];
// [nav pushViewController:c3 animated:YES];
}
创建三个子控件类及对应的xib文件
代码如下:
YYOneViewController.m文件
//
// YYOneViewController.m
// 01-导航控制器的使用1
//
// Created by apple on 14-6-4.
// Copyright (c) 2014年 itcase. All rights reserved.
//
#import “YYOneViewController.h”
#import “YYTwoViewController.h”
@interface YYOneViewController ()
/**
跳转到第二个界面
*/
– (IBAction)jump2two:(id)sender;
@end
代码如下:
@implementation YYOneViewController
– (IBAction)jump2two:(id)sender {
//1.创建第二个子控制器
YYTwoViewController *two=[[YYTwoViewController alloc]init];
//2.把子控制器添加到导航控制器中
//有什么办法能够拿到导航控制器?
//只要当前控制器是导航控制器的子控制器,那么就可以通过该属性直接获取到当前控制器所在的导航控制器
[self.navigationController pushViewController:two animated:YES];
}
@end
代码如下:
YYTwoViewController.m文件
//
// YYTwoViewController.m
// 01-导航控制器的使用1
//
// Created by apple on 14-6-4.
// Copyright (c) 2014年 itcase. All rights reserved.
//
#import “YYTwoViewController.h”
#import “YYThreeViewController.h”
@interface YYTwoViewController ()
– (IBAction)jump2Three:(id)sender;
@end
代码如下:
@implementation YYTwoViewController
//跳转到第三个子控制器
– (IBAction)jump2Three:(id)sender {
//1.创建第三个子控制器
YYThreeViewController *three=[[YYThreeViewController alloc]init];
//2.将子控制器添加到导航控制器中
[self.navigationController pushViewController:three animated:YES];
}
@end
示:只要当前控制器是导航控制器的子控制器,那么就可以通过self.navigationController属性直接获取到当前控制器所在的导
航控制器
项目文件结构和运行效果: