Definition and use of agents

Source: Internet
Author: User

1. declare an agent where the data needs to be transmitted outside

@protocol nextviewcontrollerdelegate <nsobject>

2. Declaring Proxy methods

-(void) Didloaddatawithmessage: (nsstring *) message; define or affirm

@end//Correspondence @protocol

general proxy definitions in #import < uikit/uikit.h > to between @interface

3. Defining a property implementation The agent can find this proxy through this property (more difficult to understand)

@property (nonatomic, assign)ID<nextviewcontrollerdelegate>delegate;/ /nextviewcontrollerdelegate for your proxy name

4. Proxies are generally used to transmit values and invoke proxies where they need to be passed

[self. Delegate didloaddatawithmessage:@ "hehehe"];//pass hehehe to the implementation agent

5. Introducing proxies where values are required @interface viewcontroller () <nextviewcontrollerdelegate>

6. Define the variable, hang up the proxy (with the class that declares the proxy, define the object, hang up the agent)

nextviewcontroller *nextview = [[nextviewcontroller alloc]init];

5. Hang Up Agent

NextView. delegate = self;

7. Implement the Proxy method receive the value passed over

-(void) Didloaddatawithmessage: (nsstring *) message{

NSLog(@ "%@", message);

label. Text = message;

}

Finally hope to see this article people more comments, in order to improve, of course, I do not mind everyone concerned about me, we learn together, progress together, thank you!

Definition and use of agents

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.