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];
Navigation
最新推荐文章于 2025-04-29 21:22:42 发布