IOS learning notes controller data reverse transfer value, ios2015-04-15
//// FirstViewController. h // controller data transmission // Created by wangtouwang on 15/4/15. // Copyright (c) 2015 wangtouwang. all rights reserved. // # import <UIKit/UIKit. h> @ interface FirstViewController: UIViewController @ end /// FirstViewController. m // controller data transmission /// Created by wangtouwang on 15/4/15. // Copyright (c) 2015 wangtouwang. all rights reserved. // # import "FirstViewController. h "# import" TwoViewController. h "@ interface FirstViewController () <response> {UILabel * firstLable; UITextField * firstField; UIButton * response;} @ end @ implementation FirstViewController-(void) viewDidLoad {[super viewDidLoad]; [self. view setBackgroundColor: [UIColor blackColor]; firstLable = [[UILabel alloc] initWithFrame: CGRectMake (30,100,150, 30)]; firstLable. text = @ "first page entry and exit value"; 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 = @ "incoming and outgoing values"; firstField. keyboardType = UIKeyboardTypeDefault; [self. view addSubview: firstField]; firstBtn = [[UIButton alloc] initWithFrame: CGRectMake (30,210,150, 30)]; firstBtn. backgroundColor = [UIColor colorwithred: 195/255. 0 green: 33/255. 0 blue: 30/255. 0 alpha: 1.0]; [firstBtn setTitle: @ "Jump to second page" forState: UIControlStateNormal]; [firstBtn. layer setCornerRadius: 10.0]; // set the radius of the four rounded corners of the rectangle [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 (@ "reverse transfer value"); firstField. text = result;} @ end
//// TwoViewController. h // controller data transmission // Created by wangtouwang on 15/4/15. // Copyright (c) 2015 wangtouwang. all rights reserved. // # import <UIKit/UIKit. h> @ protocol PropagateDelegate <NSObject> @ required-(void) propagateToValue :( NSString *) result; @ end @ interface TwoViewController: UIViewController @ property (nonatomic, assign) id <PropagateDelegate> delegate; @ end
//// TwoViewController. m // controller data transmission /// Created by wangtouwang on 15/4/15. // Copyright (c) 2015 wangtouwang. all rights reserved. // # import "TwoViewController. h "@ interface TwoViewController () @ property (nonatomic, strong) UILabel * firstLable; @ property (nonatomic, strong) UITextField * firstField; @ property (nonatomic, strong) UIButton * firstBtn; @ end @ implementation TwoViewController-(void) viewDidLoad {[super viewDidLoad]; [self. view setBackgroundColor: [UIColor blackColor]; _ firstLable = [[UILabel alloc] initWithFrame: CGRectMake (30,100,150, 30)]; _ firstLable. text = @ "second page entry/exit value"; _ 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 = @ "incoming and outgoing values"; _ firstField. keyboardType = UIKeyboardTypeDefault; [self. view addSubview: _ firstField]; _ firstBtn = [[UIButton alloc] initWithFrame: CGRectMake (30,210,150, 30)]; _ firstBtn. backgroundColor = [UIColor colorwithred: 195/255. 0 green: 33/255. 0 blue: 30/255. 0 alpha: 1.0]; [_ firstBtn setTitle: @ "Jump to the first page" forState: UIControlStateNormal]; [_ firstBtn. layer setCornerRadius: 10.0]; // set the radius of the four rounded corners of the rectangle [_ firstBtn addTarget: self action: @ selector (turnFirstPage :) forControlEvents: UIControlEventTouchUpInside]; [self. view addSubview: _ firstBtn];} // returns the value-(void) turnFirstPage (UIButton *) btn {[self. delegate propagateToValue: _ firstField. text]; [self. navigationController popViewControllerAnimated: NO];} @ end