//
// AppDelegate.m
// UI5_UINavigation传值
//
// Created by zhangxueming on 15/7/7.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h"
#import "ViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *rootViewController = [[ViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.window.rootViewController = nav; return YES;
}
//
// ViewController.h
// UI5_UINavigation传值
//
// Created by zhangxueming on 15/7/7.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h>
#import "SubViewController.h" @interface ViewController : UIViewController <sendTitleReport> @end //
// ViewController.m
// UI5_UINavigation传值
//
// Created by zhangxueming on 15/7/7.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h"
#import "SubViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor cyanColor]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(100, 200, self.view.frame.size.width-200, 50);
[btn setTitle:@"push" forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont boldSystemFontOfSize:24];
[btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn]; self.navigationItem.title = @"按钮一"; } - (void)btnClicked
{
NSLog(@"-------");
SubViewController *svc = [[SubViewController alloc] init];
//正向传值: 最简单的做法, 在子视图控制器中定义属性实例变量接受值
svc.delegate = self;//设置代理
svc.currentTitle = self.navigationItem.title;
[self.navigationController pushViewController:svc animated:YES];
} - (void)sendButtonTitle:(NSString *)title
{
self.navigationItem.title = title;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
//
// SubViewController.h
// UI5_UINavigation传值
//
// Created by zhangxueming on 15/7/7.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @protocol sendTitleReport <NSObject> - (void)sendButtonTitle:(NSString *)title; @end @interface SubViewController : UIViewController //记录当前被选中按钮的标题
@property (nonatomic, copy)NSString *currentTitle;
//防止相互引用
@property (assign, nonatomic) id <sendTitleReport> delegate; @end //
// SubViewController.m
// UI5_UINavigation传值
//
// Created by zhangxueming on 15/7/7.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "SubViewController.h" @interface SubViewController () @end @implementation SubViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor yellowColor];
NSArray *titles = @[@"按钮一",@"按钮二",@"按钮三"];
for (int i= 0; i<3; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(100, 100+i*100, self.view.frame.size.width-200, 50);
[btn setTitle:titles[i] forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont boldSystemFontOfSize:24];
[btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn.tag = 200+i;
//设置选中状态
if ([self.currentTitle isEqualToString:btn.currentTitle]) {
btn.selected = YES;
}
[self.view addSubview:btn];
}
} - (void)btnClicked:(UIButton *)btn
{
if([self.delegate respondsToSelector:@selector(sendButtonTitle:)])
{
[self.delegate sendButtonTitle:btn.currentTitle];
}
[self.navigationController popViewControllerAnimated:YES];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end

最新文章

  1. Spring(三)__aop编程
  2. 如何使用花生壳 发布WCF服务 进行外网访问
  3. [BZOJ2792][Poi2012]Well
  4. ACCESS自动编号重新从1开始
  5. hdu1251(字典树)
  6. epoll_create, epoll_ctl和epoll_wait
  7. 在ModelSim波形图中以参数名显示变量
  8. [CSAPP笔记][第十二章并发编程]
  9. tomcat 产生heapdump文件配置
  10. A. Vasya and Football
  11. 总结过滤器,监听器,servlet的异同点,已经执行顺序。
  12. HIT2019春软件构造-&gt;正则表达式语法
  13. Jdk_API——1.8和Jdk_API1.6下载分享
  14. 使用Mybatis Generator插件自动生成映射文件(cmd无法进入文件,dns服务器对区域没有权威等问题)遇到问题
  15. (二)Wireshark的实用表格
  16. datagridview的一些设置
  17. asp.net开发细节整理
  18. 透过摩拜和ofo,看产品从0到1时如何取舍需求(转)
  19. 【总结 】550,535,553 Mail from must equal authorized user— jenkins(hudson) email163邮箱和26邮箱成功配置总结
  20. Flutter - 左右侧滑菜单:drawer和endDrawer

热门文章

  1. Editor Scripting学习笔记之Menu Item
  2. 一步步学Mybatis-实现多表联合查询(4)
  3. Android progressBar 自定义圆形旋转图片
  4. MVC4数据注释与验证
  5. oc-21-class对象
  6. Android学习笔记之JSON数据解析
  7. Plugin with data access
  8. 项目源码--Android视频MV类网站客户端
  9. 1.4.10 Schemaless模式
  10. Cache的原理、设计及实现