UINavigationController

标题

UINavigationController的创建和应用

//头文件
#import "MainViewController.h"

先创建一个viewController
MainViewController *mainVC = [[MainViewController alloc]init];
//创建导航视图控制器
UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:mainVC];
//添加根视图控制器  
self.window.rootViewController = naVC;
//释放
[naVC release];
[mainVC release];

在视图控制器中添加控件 控件的加载内容不详述

//这里的button是为了实现点击跳转的方法
[button setTitle:@"下一页" forState:UIControlStateNormal];
[self.view addSubview:button];
button.layer.borderWidth = 1;
button.layer.cornerRadius = 10;
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

对UINavigationController进行设置

//加上一个标题
self.title = @"猫眼电影";
//外观进行设置
//背景颜色的设置
//不是所有的背景颜色都是backgrandColor
self.navigationController.navigationBar.barTintColor = [UIColor grayColor];
//为了防止坐标系被篡改,我们把bar从半透明设置成不透明,这样坐标系的原点会自动向下推64
self.navigationController.navigationBar.translucent = NO;
//标题设置(效果与self.title大致相同 至于功能有什么区别不太清楚)
//self.navigationItem.title = @"鹰王电影";
//创建左右两边的按钮
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(barButtonAction:)] autorelease];
//可以重写左右两边的按钮并在按钮上添加自定义的图片
//创建一个小button
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
rightButton.frame = CGRectMake(0, 0, 40, 40);
[rightButton setImage:[UIImage imageNamed:@"star.png"] forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];

实现按钮的点击事件 这里有两种跳转方法模态跳转和导航视图控制器的跳转(可以通过属性传值)

//用模态跳转下一页
SecondViewController *secVC = [[SecondViewController alloc]init];
[secVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
//completion是block系统的block不需要写方法
[self presentViewController:secVC animated:YES completion:^{

}];
[secVC release];
////////////////////////////////////////////////////////////////////
//第二种方法 通过导航视图控制器进行跳转
通过导航视图控制器进行跳转
创建下一页对象
SecondViewController *secVC = [[SecondViewController alloc]init];
//通过.navigationController属性调出当前管理者
[self.navigationController pushViewController:secVC animated:YES];
//内存管理
[secVC release];
//下面的属性通过对象调用进行赋值并传值 属性需要在声明对象的.h文件中声明
secVC.number = 100;
secVC.str = self.myTextField.text;
secVC.arr = @[@"杨林",@"刘山山"];

从后往前跳转 需要在被跳转页写方法

//这里的popTo属性是枚举型不同的情况需要不同的方法
-(void)click:(UIButton *)button{
//从后往前跳
//跳到根视图
[self.navigationController popToRootViewControllerAnimated:YES];
//跳到跳转本视图的视图
[self.navigationController popViewControllerAnimated:YES];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值