The value of the value of the transfer between IOS pages, agent value

Source: Internet
Author: User

Mobile Phone APP Run, the value of the transfer between different pages is necessary, there are many ways to pass the value (method transfer value, attribute transfer value, proxy value, single-pass value), here is the main summary of the value of the property and proxy value.

Property pass-through value: The value of the property is the simplest and most common way of transmitting value, but it has limitations (generally used to pass the value of the first page to the second page, but not from the second page to the first page),

Pass value to Secondviewcontroller:secondviewcontroller Set Property 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 }

Proxy value: Difficult, hard to understand, typically used to pass values to the first page on the second page. Generally divided into six steps

(Example using Navigationcontroller jump page)

1. Statement of Agreement (written on the second page)

@protocol mydelegete <nsobject>-(void) SendMessage: (nsstring*) message; @end

2. Define the properties of the Compliance Agreement (written on the second page) (attributes must be assign )

@property (nonatomic, assign)IDdelegate;

3. Compliance Agreement (written on the first page)

1 @interface <myDelegete>

4. Set proxy (set Agent to write in jump event) (write on 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   Proxy value Fourth step  6  SECONDVC. delegate  = self;  7  8 }  

5. Implementing the Protocol Method (written on the first page)

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

6. Implement the value of the pass (written on the second page)

1 -(void) Leftbuttonaction: (Uibarbuttonitem *) sender{2    [ Self.navigationcontroller Popviewcontrolleranimated:yes]; 3     // Agent Value Sixth step: 4     [Self. Delegate SendMessage:self.secondView.textField.text]; 5 }

The value of the value of the transfer between IOS pages, agent value

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.