IOS learning notes controller data reverse transfer value, ios2015-04-15

Source: Internet
Author: User

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.