Attribute Value Transfer Between iOS pages, proxy value transfer, and ios page

Source: Internet
Author: User

Attribute Value Transfer Between iOS pages, proxy value transfer, and ios page

When the mobile APP is running, it is essential to pass values between different pages. There are many ways to pass values (method-based value transfer, attribute-based value transfer, proxy-based value transfer, and single-case value transfer ), here we will mainly summarize the attribute value passing and proxy value passing.

Attribute Value passing: attribute value passing is the simplest and most common value passing method, but it has limitations (generally used to pass the value of the first page to the second page, but it cannot be uploaded from the second page to the first page ),

Send a value to SecondViewController: SecondViewController sets the attribute sendMessage

1 - (void)rightButtonAction:(UIBarButtonItem *)sender{2     SecondViewController *secondVC = [[SecondViewController alloc]init];3     secondVC.sendMessage = self.rootView.textField.text;4     [self.navigationController pushViewController:secondVC animated:YES];5 }

 

Value passing by proxy: difficult and difficult to understand. It is usually used to pass a value to the first page on the second page. Generally, it is divided into six steps.

(This example uses navigationController to jump to the page)

1. Declare the Protocol (written on the second page)

@protocol myDelegete <NSObject>- (void)sendMessage:(NSString*)message;@end

 

2. Define the protocol-compliant attributes (written on the second page) (assign is required for the attributes)

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

 

3. comply with the agreement (written on the first page)

1 @interface RootViewController : UIViewController <myDelegete>

 

4. Set the proxy (set the proxy to be written in the jump event) (written on the first page)

 

1-(void) rightButtonAction :( UIBarButtonItem *) sender {2 SecondViewController * secondVC = [[SecondViewController alloc] init]; 3 secondVC. sendMessage = self. rootView. textField. text; 4 [self. navigationController pushViewController: secondVC animated: YES]; 5 // The fourth step 6 secondVC. delegate = self; 7 8}

 

 

 

5. Implementation Protocol method (written on the first page)

 

1 - (void)sendMessage:(NSString *)message{2     self.rootView.textField.text = message;3 }

 

 

 

6. Implement value transfer (written on the second page)

1-(void) leftButtonAction :( UIBarButtonItem *) sender {2 [self. navigationController popViewControllerAnimated: YES]; 3 // Step 6: 4 [self. delegate sendMessage: self. secondView. textField. text]; 5}

 

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.