标签:
// // AppDelegate.m // 页面传值总结 // // Created by qianfeng on 15/6/13. // Copyright (c) 2015年 qianfeng. All rights reserved. // #import "AppDelegate.h" #import "ViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ViewController *ctr = [[ViewController alloc]init]; UINavigationController*nav = [[UINavigationController alloc]initWithRootViewController:ctr]; self.window.rootViewController = nav; return YES; }
// // ViewController.m // 页面传值总结 // // Created by qianfeng on 15/6/13. // Copyright (c) 2015年 qianfeng. All rights reserved. // #import "ViewController.h" #import "DetailVIewController.h" @interface ViewController () { UILabel*_label; } @property(nonatomic,strong)UILabel*label; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; //用于显示第二个界面传过来的数据。 _label = [[UILabel alloc]initWithFrame:CGRectMake(120, 220, 100, 40)]; _label.backgroundColor = [UIColor orangeColor]; [self.view addSubview:_label]; //创建用于跳转到第二个界面的按钮; UIButton*btn = [self createBtnFrame:CGRectMake(120, 300, 100, 40) title:@"跳转" target:self action:@selector(clickBtn:)]; btn.backgroundColor = [UIColor grayColor]; [self.view addSubview:btn]; } -(void)clickBtn:(id)sender { DetailVIewController*ctr = [[DetailVIewController alloc]init]; __weak ViewController*weakself =self; ctr.clockBlock = ^(NSString*title){ weakself.label.text = title; }; [self.navigationController pushViewController:ctr animated:YES]; } -(UIButton*)createBtnFrame:(CGRect)frame title:(NSString*)title target:(id)target action:(SEL)action { UIButton*btn= [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = frame; [btn setTitle:title forState:UIControlStateNormal]; [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; return btn; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
标签:
原文地址:http://www.cnblogs.com/0515offer/p/4641299.html