IOS UI07 _ pass value on the Interface

Source: Internet
Author: User

IOS UI07 _ pass value on the Interface

//// MainViewController. m // UI07 _ input value /// Created by dllo on 15/8/6. // Copyright (c) 2015 zhozhicheng. all rights reserved. // # import MainViewController. h # import SecondViewController. h // 4. sign the agreement @ interface MainViewController ()
  
   
@ Property (nonatomic, retain) UILabel * label; @ property (nonatomic, retain) UIButton * button; @ end @ implementation MainViewController-(void) dealloc {[_ label release]; [_ button release]; [super dealloc];}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. self. view. backgroundColor = [UIColor orangeColor]; // set to Opacity self. navigationController. navigationBar. translucent = NO; self. title = @ page 1; self. label = [[UILabel alloc] initWithFrame: CGRectMake (100,100,100, 40)]; self. label. backgroundColor = [UIColor yellowColor]; [self. view addSubview: self. label]; [self. label release]; UIButton * button = [UIButton buttonWithType: UIButtonTypeSystem]; button. frame = CGRectMake (100,200,100, 40); [button setTitle: @ next page forState: UIControlStateNormal]; button. layer. borderWidth = 1; button. layer. cornerRadius = 10; [self. view addSubview: button]; [button addTarget: self action: @ selector (click :) forControlEvents: UIControlEventTouchUpInside];}-(void) click :( UIButton *) button {SecondViewController * secVC = [[SecondViewController alloc] init]; [self. navigationController pushViewController: secVC animated: YES]; [secVC release]; // 5. set the proxy secVC. delegate = self;} // 6. implementation Protocol method-(void) changeValue :( NSString *) value {NSLog (% @, value); self. label. text = value;}-(void) didreceivemorywarning {[super didreceivemorywarning]; // 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
  
//// SecondViewController. h // UI07 _ input value /// Created by dllo on 15/8/6. // Copyright (c) 2015 zhozhicheng. all rights reserved. // # import
  
   
// The first step to pass the protocol value // 1. Declare the protocol @ protocol SecondViewControllerDelegate
   
    
// Protocol method-(void) changeValue :( NSString *) value; @ end @ interface SecondViewController: UIViewController // 2. Set the proxy attribute @ property (nonatomic, assign) id
    
     
Delegate; @ end
    
   
  
//// SecondViewController. m // UI07 _ input value /// Created by dllo on 15/8/6. // Copyright (c) 2015 zhozhicheng. all rights reserved. // # import SecondViewController. h @ interface SecondViewController () // A textfield a button @ property (nonatomic, retain) UITextField * textfield; @ property (nonatomic, retain) UIButton * button; @ end @ implementation SecondViewController-(void) dealloc {[_ button release]; [_ textfield release]; [super dealloc];}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. self. view. backgroundColor = [UIColor cyanColor]; self. title = @ page 2; UIButton * button = [UIButton buttonWithType: UIButtonTypeSystem]; button. frame = CGRectMake (100,200,100, 40); [button setTitle: @ return forState: UIControlStateNormal]; button. layer. borderWidth = 1; button. layer. cornerRadius = 10; [self. view addSubview: button]; [button addTarget: self action: @ selector (click :) forControlEvents: UIControlEventTouchUpInside]; self. textfield = [[UITextField alloc] initWithFrame: CGRectMake (100,100,100, 40)]; self. textfield. layer. borderWidth = 1; self. textfield. layer. cornerRadius = 10; [self. view addSubview: self. textfield]; [self. textfield release];} // The trigger condition of the protocol is to click the button, so the third step of passing the value of the protocol here // 3. method for setting the proxy to execute the protocol-(void) click :( UIButton *) button {[self. navigationController popToRootViewControllerAnimated: YES]; [self. delegate changeValue: self. textfield. text];}-(void) didreceivemorywarning {[super didreceivemorywarning]; // 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

 

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.