首先, 先创建三个VC.

完毕点击按钮, 进入下一页, 并可以返回.

要先把导航视图控制器创建出来.

在AppDelegate.m 文件里代码例如以下:

#import "AppDelegate.h"
#import "MainViewController.h"
@interface AppDelegate ()
@end @implementation AppDelegate
- (void)dealloc{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[_window release]; //先创建一个ViewController
MainViewController *mainVC = [[MainViewController alloc] init];
//创建导航视图控制器
UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:mainVC];
self.window.rootViewController = navC;
//释放
[mainVC release];
[navC release]; return YES;
}

对于导航视图控制器的一些设置.

  //导航视图控制器的高度是44,上面的状态栏高度是20,加在一起默认是64;
// 加上一个标题.
self.title = @"猫眼电影";
// 对外观进行设置,不是全部的颜色都是BackgroundColor;
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
  // 创建一个UIView
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view.backgroundColor = [UIColor orangeColor];
[self.view addSubview:view];
[view release];
// 为了防止坐标系被篡改,我们把bar从半透明改为全透明.这样坐标系的原点会自己主动向下推64
self.navigationController.navigationBar.translucent = NO;

内容方面的设置


//另外一种标题的设置
self.navigationItem.title = @"骨头 商店"; // 指定一些视图,作为titleView
UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"信息",@"通话"]];
self.navigationItem.titleView = seg;
[seg release];

创建左右两个按钮

    //左按钮
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemOrganize target:self action:@selector(leftAction:)] autorelease]; //右按钮
//如此创建,原本拖拽的图标的颜色是黄色,但这么创建后,图标是蓝色的.
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"狗.png"] style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)] autorelease]; // 以下方法图标将会显示黄色.
// 创建一个小button,把图片装上.
UIButton *Littlebutton = [UIButton buttonWithType:UIButtonTypeCustom];
Littlebutton.frame = CGRectMake(0, 0, 40, 40);
[Littlebutton setImage:[UIImage imageNamed:@"狗.png"] forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:Littlebutton]; UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(260, 530, 80, 40);
button.backgroundColor = [UIColor yellowColor];
[self.view addSubview:button];
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
button.layer.cornerRadius = 10;
[button setTitle:@"下一页" forState:UIControlStateNormal];

对应的, 左右两个按钮的点击事件也要实现

- (void)rightAction:(UIBarButtonItem *)button{
} - (void)leftAction:(UIBarButtonItem *)barButton{
}

点击Button跳转到下一页.

用模态也可以跳转 , 可是跳转的页面不再有导航视图.

实现Button的点击事件

当中我要完毕从前向后传值.

- (void)click:(UIButton *)button{
- // 用导航视图控制器跳转.
//1.先创建下一页对象.
SecondViewController *secondVC = [[SecondViewController alloc] init];
//通过导航控制器找到
[self.navigationController pushViewController:secondVC animated:YES];
[secondVC release]; // 属性传值第二步
secondVC.number = 100;
secondVC.string = self.textField.text;
secondVC.arr = @[@"haha",@"啦啦"];
}

第二个页面的 .h 中代码:

#import <UIKit/UIKit.h>

@interface SecondViewController : UIViewController
// 属性传值第一步,在第二个页面写一条属性.
@property(nonatomic, assign)NSInteger number; //属性传值另外一种: 针对TextField中的字符串写一条属性.
@property(nonatomic, copy)NSString *string; //属性传值第三种: 传一个数组
@property(nonatomic, retain)NSArray *arr; @end

第二个页面的 .m 中代码:

#import "SecondViewController.h"
#import "ThirdViewController.h"
@interface SecondViewController ()
@property(nonatomic, retain)UILabel *label;
@end @implementation SecondViewController
- (void)dealloc{
[_label release];
[_string release];
[_arr release];
[super dealloc];
} - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor yellowColor];
self.navigationController.navigationBar.barTintColor = [UIColor magentaColor]; UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(260, 530, 80, 40);
button.backgroundColor = [UIColor blueColor];
[self.view addSubview:button];
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
button.layer.cornerRadius = 10;
[button setTitle:@"下一页" forState:UIControlStateNormal]; //第三步:
//第一种:
NSLog(@"%ld",self.number); //另外一种:
self.label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];
[self.view addSubview:self.label];
[_label release];
self.label.layer.borderWidth = 1; //属性传值第三步:里面的值赋给label
self.label.text = self.string;
// 第三种:
NSLog(@"%@",self.arr[1]);
}
- (void)click:(UIButton *)button{
ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
[self.navigationController pushViewController:thirdVC animated:YES];
[thirdVC release];
}

属性传值. 传NSIntger . NSString . NSArray

最新文章

  1. 【敏捷开发】Android团队开发规范
  2. deployment与Web应用程序部署
  3. 使用数据泵+dblink迁移数据库,适用于本地空间不足的情况
  4. 导师互选系统 Alpha版冲刺总结
  5. Mac OS 上设置 JAVA_HOME
  6. h5audio标签
  7. 第3阶段——内核启动分析之make menuconfig内核配置(2)
  8. 读汤姆大叔《JavaScript变量对象》笔记
  9. Spark1.6之后为何使用Netty通信框架替代Akka
  10. vue中v-model动态生成的实例详解
  11. Django ORM 反向查询
  12. Git坑点——remote: error: GH007: Your push would publish a private email address.
  13. SPI OLED 驱动
  14. java把指定文字输出为图片流,支持文字换行
  15. ML、DL相关资源
  16. C# .net微信开发,开发认证,关注触发消息,自动应答,事件响应,自定义菜单
  17. easyui 特殊操作
  18. Office 365实现单点登录系列(2)—Azure AD Connect安装与配置
  19. Hibernate 中 load() 方法导致的 noSession 异常
  20. swift 运算符和控制流程

热门文章

  1. 使用snapshot继续训练网络
  2. docker部署xxl-job
  3. [JOYOI] 1124 花店橱窗
  4. xenserver tools 安装
  5. 条款17:以独立语句将newed对象置入智能指针(Store newed objects in smart pointers in standalone statements)
  6. uC/OSii之任务划分
  7. 【BZOJ 1076】[SCOI2008]奖励关(期望)
  8. sql无效字符 执行sql语句报错解决方案
  9. Python+fiddler(基于Cookie绕过验证码自动登录)
  10. MySql查询语句的使用实例