IOS学习笔记2015-04-15控制器数据反向传值

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

////FirstViewController.h//控制器数据传递////Created by wangtouwang on 15/4/15.//Copyright (c) 2015年 wangtouwang. All rights reserved.//#import<UIKit/UIKit.h>@interfaceFirstViewController : UIViewController@end////FirstViewController.m//控制器数据传递////Created by wangtouwang on 15/4/15.//Copyright (c) 2015年 wangtouwang. All rights reserved.//#import"FirstViewController.h"#import"TwoViewController.h"@interfaceFirstViewController ()<PRopagateDelegate>{

UILabel*firstLable;

UITextField*firstField;

UIButton*firstBtn;

}@end@implementationFirstViewController- (void)viewDidLoad {

[super viewDidLoad];

[self.view setBackgroundColor:[UIColor blackColor]];

firstLable= [[UILabel alloc] initWithFrame:CGRectMake(30,100,150,30)];

firstLable.text=@"第一页面进出值";

firstLable.font=[UIFont systemFontOfSize:15.0];

firstLable.textColor=[UIColor whiteColor];

[self.view addSubview:firstLable];

firstField= [[UITextField alloc] initWithFrame:CGRectMake(30,150,150,30)];

firstField.textColor=[UIColor blackColor];

firstField.font=[UIFont fontWithName:@"Arial"size:14.0];

firstField.borderStyle=UITextBorderStyleRoundedRect;

firstField.placeholder=@"进出值";

firstField.keyboardType=UIKeyboardTypeDefault;

[self.view addSubview:firstField];

firstBtn= [[UIButton alloc] initWithFrame:CGRectMake(30,210,150,30)];

firstBtn.backgroundColor=[UIColor colorWithRed:195/255.0green:33/255.0blue:30/255.0alpha:1.0];

[firstBtn setTitle:@"跳转第二页面"forState:UIControlStateNormal];

[firstBtn.layer setCornerRadius:10.0];//设置矩形四个圆角半径[firstBtn addTarget:self action:@selector(turnTwoPage:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:firstBtn];

}-(void)turnTwoPage:(UIButton *)btn{

TwoViewController*two =[[TwoViewController alloc] init];

two.delegate=self;

[self.navigationController pushViewController:two animated:NO];

}-(void)propagateToValue:(NSString *)result{

NSLog(@"反向传值");

firstField.text=result;

}@end

////TwoViewController.h//控制器数据传递////Created by wangtouwang on 15/4/15.//Copyright (c) 2015年 wangtouwang. All rights reserved.//#import<UIKit/UIKit.h>@protocolPropagateDelegate <NSObject>@required-(void)propagateToValue:(NSString *)result;@end@interfaceTwoViewController : UIViewController

@property(nonatomic,assign)id<PropagateDelegate>delegate;@end

////TwoViewController.m//控制器数据传递////Created by wangtouwang on 15/4/15.//Copyright (c) 2015年 wangtouwang. All rights reserved.//#import"TwoViewController.h"@interfaceTwoViewController ()

@property(nonatomic,strong) UILabel*firstLable;

@property(nonatomic,strong) UITextField*firstField;

@property(nonatomic,strong) UIButton*firstBtn;@end@implementationTwoViewController- (void)viewDidLoad {

[super viewDidLoad];

[self.view setBackgroundColor:[UIColor blackColor]];

_firstLable= [[UILabel alloc] initWithFrame:CGRectMake(30,100,150,30)];

_firstLable.text=@"第二页面进出值";

_firstLable.font=[UIFont systemFontOfSize:15.0];

_firstLable.textColor=[UIColor whiteColor];

[self.view addSubview:_firstLable];

_firstField= [[UITextField alloc] initWithFrame:CGRectMake(30,150,150,30)];

_firstField.textColor=[UIColor blackColor];

_firstField.font=[UIFont fontWithName:@"Arial"size:14.0];

_firstField.borderStyle=UITextBorderStyleRoundedRect;

_firstField.placeholder=@"进出值";

_firstField.keyboardType=UIKeyboardTypeDefault;

[self.view addSubview:_firstField];

_firstBtn= [[UIButton alloc] initWithFrame:CGRectMake(30,210,150,30)];

_firstBtn.backgroundColor=[UIColor colorWithRed:195/255.0green:33/255.0blue:30/255.0alpha:1.0];

[_firstBtn setTitle:@"跳转第一页面"forState:UIControlStateNormal];

[_firstBtn.layer setCornerRadius:10.0];//设置矩形四个圆角半径[_firstBtn addTarget:self action:@selector(turnFirstPage:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:_firstBtn];

}//反向传值-(void)turnFirstPage:(UIButton *)btn{

[self.delegatepropagateToValue:_firstField.text];

[self.navigationController popViewControllerAnimated:NO];

}@end

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航