Navigation

Navigation 导航栏
1.声明.若第一个页面显示则在AppDelegate.h声明,其他页面则在当前页面的.m中声明
@property(strong, nonatomic) UINavigationController *naviVC;
2.初始化
若是第一个页面显示
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
ViewController *theFirstWindow = [[ViewController alloc]init];
self.naviVC = [[UINavigationController alloc]initWithRootViewController:theFirstWindow];
[self.window setRootViewController:self.naviVC];
[self.window makeKeyAndVisible];
若其他页面显示,则在初始化函数中
有以下两种方法:
1:
self.naviVC = [[UINavigationController alloc] initWithRootViewController:self];
[[UIApplication sharedApplication].keyWindow setRootViewController:self.naviVC];
2:
self.naviVC = [[UINavigationController alloc] init];
[self.naviVC pushViewController:self animated:YES];//把自己加载
[[UIApplication sharedApplication].keyWindow setRootViewController:self.naviVC];
//[UIApplication sharedApplication].keyWindow是self.windows
3.显示主题
theFirstWindow.title = @“我的会员卡”;
4.添加UIBarButtonItem
//左边是搜索按钮
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(selectLeftAction:)];
self.navigationItem.leftBarButtonItem = leftButton;
//右边是添加按钮
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(selectRightAction:)];
self.navigationItem.rightBarButtonItem = rightButton;
5.响应UIBarButtonItem的事件的实现
//相应左边的搜索按钮
-(void)selectLeftAction:(id)sender
{
}
//相应右边的增加按钮
-(void)selectRightAction:(id)sender
{
}
6.实现页面跳转
新建一个页面,UIViewController即可(含xlb),则跳转后自动含有back
addCard *addCardNum = [[addCard alloc] init];
[self.navigationController pushViewController:addCardNum animated:YES];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值