导航控制器(UINaigationControl)
来源:互联网 发布:怎么在淘宝买病假条 编辑:程序博客网 时间:2024/05/29 10:22
第一个页面FirstViewController.m
- (void)viewDidLoad{ [super viewDidLoad];// Do any additional setup after loading the view. UIImageView * showView = [[UIImageView alloc]initWithFrame:CGRectMake(60, 0, 200, 400)]; showView.image = [UIImage imageNamed:@"showPic"]; [self.view addSubview:showView]; [showView release]; //导航栏的样式 //白色的透明的导航栏 //self.navigationController.navigationBar.barStyle = UIBarStyleDefault; //黑色的透明的导航栏 //self.navigationController.navigationBar.barStyle = UIBarStyleBlack; //设置非透明的导航栏 //self.navigationController.navigationBar.translucent = NO; //设置背景颜色 //self.navigationController.navigationBar.barTintColor = [UIColor purpleColor]; //设置按钮颜色 //self.navigationController.navigationBar.tintColor = [UIColor greenColor]; [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"NavBar_44.png"] forBarMetrics:UIBarMetricsDefault]; self.view.backgroundColor = [UIColor redColor]; UILabel * firstLable = [[UILabel alloc] initWithFrame:CGRectMake(60, 100, 200, 40)]; self.navigationItem.title = @"First"; //self.navigationItem.titleView = //[UIImage imageNamed:@"NavBtnLeft.png" ]; //设置 导航栏 左侧 右侧 //系统定义// UIBarButtonItem * rightButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:(UIBarButtonSystemItemFastForward) target:self action:@selector(didClickPushButtonAction)];// self.navigationItem.rightBarButtonItem = rightButtonItem; //自定义 UIBarButtonItem * rightButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"下一页" style:UIBarButtonItemStyleBordered target:self action:@selector(didClickPushButtonAction)]; self.navigationItem.rightBarButtonItem = rightButtonItem; // UIBarButtonSystemItem * life = [UIBarButtonItem alloc]=rightButtonItem; firstLable.text = @"第一页"; firstLable.backgroundColor = [UIColor redColor]; firstLable.textAlignment = NSTextAlignmentCenter; [self.view addSubview:firstLable]; [firstLable release]; UIButton * pushButton = [UIButton buttonWithType:UIButtonTypeSystem]; pushButton.frame = CGRectMake(100, 200, 100, 100); [pushButton setTitle:@"push" forState:UIControlStateNormal ]; [pushButton addTarget:self action:@selector(didClickPushButtonAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:pushButton]; NSLog(@"我是加载页面%s,%d",__FUNCTION__,__LINE__); }-(void)didClickPushButtonAction{ //导航控制器 push(推出) 下一个页面 second对象 //UIViewController 的类目中,声明了一个属性:navigationController.UIViewController被导航控制器管理时,这个属性就是管理他的导航控制器对象 //在push之前,只有controller对象,还没有view //如果在push之前使用controller的view,controller会提前创建view对象 //所以,在push之前,可以使用contrliler对象,但是不要操作controller的view SecondViewController * secondVC = [[SecondViewController alloc] init]; [self.navigationController pushViewController:secondVC animated:YES];}-(void)viewDidAppear:(BOOL)animated{ NSLog(@"第一个页面出现%s,%d",__FUNCTION__,__LINE__);}-(void)viewWillAppear:(BOOL)animated{ NSLog(@"第一个页面将要出现%s,%d",__FUNCTION__,__LINE__);// [[self navigationController] setNavigationBarHidden:NO animated:YES];}-(void)viewDidDisappear:(BOOL)animated{ NSLog(@"第一个页面消失%s,%d",__FUNCTION__,__LINE__);}-(void)viewWillDisappear:(BOOL)animated{ NSLog(@"第一个页面将要消失%s,%d",__FUNCTION__,__LINE__);}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. NSLog(@"内存警告%s,%d",__FUNCTION__,__LINE__); if ([self isViewLoaded] && self.view.window == nil) { self.view = nil; }}
第二个页面SecondViewControlle.m
//初始化 UIBarButtonItem * rightButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"上一页" style:UIBarButtonItemStyleBordered target:self action:@selector(didClickPopToLastAction)]; self.navigationItem.leftBarButtonItem = rightButtonItem; self.view.backgroundColor = [UIColor greenColor]; self.navigationController.navigationBar.barTintColor = [UIColor magentaColor]; self.navigationItem.title = @"second"; //坐边两个同时存在 self.navigationItem.leftItemsSupplementBackButton = YES; self.navigationItem.prompt = @"wowwww"; UILabel * firstLable = [[UILabel alloc] initWithFrame:CGRectMake(60, 100, 200, 40)]; firstLable.text = @"第二页"; firstLable.backgroundColor = [UIColor redColor]; firstLable.textAlignment = NSTextAlignmentCenter; [self.view addSubview:firstLable]; [firstLable release]; UIButton * pushButton = [UIButton buttonWithType:UIButtonTypeSystem]; pushButton.frame = CGRectMake(100, 200, 100, 100); [pushButton setTitle:@"push" forState:UIControlStateNormal ]; [pushButton addTarget:self action:@selector(didClickPushButtonAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:pushButton]; UIButton * PopToLast = [UIButton buttonWithType:UIButtonTypeSystem]; PopToLast.frame = CGRectMake(200, 100, 100, 100); [PopToLast setTitle:@"PopToLast" forState:UIControlStateNormal ]; [PopToLast addTarget:self action:@selector(didClickPopToLastAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:PopToLast]; NSLog(@"我是加载页面%s,%d",__FUNCTION__,__LINE__);// [[self navigationController] setNavigationBarHidden:YES animated:YES]; }-(void)didClickPopToLastAction{// FirstViewController * firstVC = [[FirstViewController alloc]init];// [self.navigationController popToViewController:firstVC animated:YES]; [self.navigationController popViewControllerAnimated:YES];}-(void)didClickPushButtonAction{ //导航控制器 push(推出) 下一个页面 second对象 //UIViewController 的类目中,声明了一个属性:navigationController.当UIViewController被导航控制器管理时,这个属性就是管理他的导航控制器对象 ThirdViewController * thirdVC = [[ThirdViewController alloc] init]; [self.navigationController pushViewController:thirdVC animated:YES]; }
第三个页面
ThirdViewController.m
- (void)viewDidLoad{ [super viewDidLoad];// Do any additional setup after loading the view. self.view.backgroundColor = [UIColor orangeColor]; UIButton * pushButton = [UIButton buttonWithType:UIButtonTypeSystem]; pushButton.frame = CGRectMake(100, 200, 100, 100); [pushButton setTitle:@"push" forState:UIControlStateNormal ]; [pushButton addTarget:self action:@selector(didClickPushButtonAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:pushButton]; UIButton * PopToLast = [UIButton buttonWithType:UIButtonTypeSystem]; PopToLast.frame = CGRectMake(200, 100, 100, 100); [PopToLast setTitle:@"PopToLast" forState:UIControlStateNormal ]; [PopToLast addTarget:self action:@selector(didClickPopToLastAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:PopToLast]; UIButton * PopToRoot = [UIButton buttonWithType:UIButtonTypeSystem]; PopToRoot.frame = CGRectMake(50, 100, 100, 100); [PopToRoot setTitle:@"PopToRoot" forState:UIControlStateNormal ]; [PopToRoot addTarget:self action:@selector(didClickPopToRootAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:PopToRoot]; UILabel * firstLable = [[UILabel alloc] initWithFrame:CGRectMake(60, 100, 200, 40)]; firstLable.text = @"第三页"; firstLable.backgroundColor = [UIColor redColor]; firstLable.textAlignment = NSTextAlignmentCenter; [self.view addSubview:firstLable]; [firstLable release]; }-(void)didClickPopToRootAction{ [self.navigationController popToRootViewControllerAnimated:YES];}-(void)didClickPopToLastAction{ [self.navigationController popViewControllerAnimated:YES];}-(void)didClickPushButtonAction{ //导航控制器 push(推出) 下一个页面 second对象 //UIViewController 的类目中,声明了一个属性:navigationController.当UIViewController被导航控制器管理时,这个属性就是管理他的导航控制器对象 FourthViewController* fourthVC = [[FourthViewController alloc] init]; [self.navigationController pushViewController:fourthVC animated:YES];}
第四个页面FourthViewController.m
- (void)viewDidLoad{ [super viewDidLoad];// Do any additional setup after loading the view. self.view.backgroundColor = [UIColor purpleColor]; UIButton * PopToLast = [UIButton buttonWithType:UIButtonTypeSystem]; PopToLast.frame = CGRectMake(200, 100, 100, 100); [PopToLast setTitle:@"PopToLast" forState:UIControlStateNormal ]; [PopToLast addTarget:self action:@selector(didClickPopToLastAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:PopToLast]; UIButton * PopToRoot = [UIButton buttonWithType:UIButtonTypeSystem]; PopToRoot.frame = CGRectMake(50, 100, 100, 100); [PopToRoot setTitle:@"PopToRoot" forState:UIControlStateNormal ]; [PopToRoot addTarget:self action:@selector(didClickPopToRootAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:PopToRoot]; UIButton * PopToAny = [UIButton buttonWithType:UIButtonTypeSystem]; PopToAny.frame = CGRectMake(120, 200, 100, 100); [PopToAny setTitle:@"返回第二页" forState:UIControlStateNormal ]; [PopToAny addTarget:self action:@selector(didClickPopToAnyAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:PopToAny]; UILabel * firstLable = [[UILabel alloc] initWithFrame:CGRectMake(60, 100, 200, 40)]; firstLable.text = @"第四页"; firstLable.backgroundColor = [UIColor redColor]; firstLable.textAlignment = NSTextAlignmentCenter; [self.view addSubview:firstLable]; [firstLable release];}-(void)didClickPopToAnyAction{ //导航控制器的viewControllers(栈)中,根据index,获取secondVC对象. SecondViewController * secondVC =[self.navigationController.viewControllers objectAtIndex:1]; [self.navigationController popToViewController:secondVC animated:YES];}-(void)didClickPopToRootAction{ [self.navigationController popToRootViewControllerAnimated:YES];}-(void)didClickPopToLastAction{ [self.navigationController popViewControllerAnimated:YES];}
0 0
- 导航控制器(UINaigationControl)
- 导航控制器(二 自定义UINaigationControl)
- 导航控制器
- 导航控制器
- 导航控制器
- 导航控制器
- 导航控制器
- 导航控制器
- 导航控制器
- 导航控制器
- 导航控制器
- 控制器和导航控制器
- 导航控制器及TabBar控制器
- 导航控制器和标签控制器
- 控制器 ------ tabbar控制器 和 导航控制器
- XCode 4.2 导航控制器
- 导航视图控制器UINavigationController
- IOS导航控制器
- 高效率能人的7个习惯
- effective c++ 条款12 赋值对象时勿忘其每一个成员
- 关于MyEclipse从SVN上checkout项目可能出现的问题
- 经验总结13--EF配置
- HDU 2243 ac自动机
- 导航控制器(UINaigationControl)
- 千万级并发HAproxy均衡负载系统介绍
- tomcat访问127.0.0.1:8080和本地ip访问失败
- virtualbox下为ubuntu扩大硬盘
- (ZZ) SCTP 流控制传输协议(一)
- iOS8 新特性
- 2-SAT 问题
- bias and variance
- Flex4 AIR程序去除窗口边框, 最大化