Transfer values between IOS pages (presenter delegate)

Source: Internet
Author: User

iOS delegate, the popular point is that the value of the page between the transfer.

There are three ways to sum up the value of the iOS page you know now

1. Send a value for notifications using Nsnotification

The main is to send a notification through the nsnotificationcenter, he does not know to pass the value to who, when listens the page receives the notification message, only then obtains the message.

2. Is the use of the property to pass the value, I mainly use the a->b a page to jump to the B page, you will need a in B to pass the Preparfrosegue method from A to B

3. By Nsuserdefault, the main idea is to write the value to a localized file, when another page needs to go back to this file by URL

4. Through the delegate to transmit the value, as long as the A->b page jump, when the operation in B after the completion of the operation in B to the data on a page display, this time to use the delegate

First of all: we need to declare a delegate in B

The code in B.h is as follows

@protocol hbaddpersontableviewcontrollerdelegate; @interface Hbaddpersontableviewcontroller:uitableviewcontroller@property (nonatomic, Strong) ID Delegate ; @end @protocol Hbaddpersontableviewcontrollerdelegate <nsobject>-(void) Savepayerorconsumer: (Nsarray *) Usersinfo Istocunsumer: (bool) Istoconsume Istopayer: (bool) Istopayer; @end

The code in B.M is as follows

-(Ibaction) Completebuttonclick: (ID) sender{if(self.  Delegate) {[Self. Delegate savepayerorconsumer:_selectcontact Istocunsumer:_iscomefromgetconsumer istopayer:_iscomefromgetpayer];}}

Where a page is to declare this delegate, and in the. m file to implement the declared method, the value of the parameter is a number in B

Transfer values between IOS pages (presenter delegate)

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.