Use of agents in IOS OC

Source: Internet
Author: User

Create an empty Project

In the project we create a new class of inheritance and NSObject

Define a protocol '

@protocol updatealertdelegate <NSObject>//The red font here is the name of the protocol we define

-(void) Updatealert;//This is a method that must be implemented for a class to follow this protocol, with or without parameters depending on the case

@end

@interface Timercontrol:nsobject

@property (nonatomic, weak) id<updatealertdelegate> delegate;

@end

In the file implemented by this Protocol class

When you need to delegate another class to do something

We can write this line of code in the implementation file for this Protocol class.

[self. Delegate Updatealert];

In the class to which this agreement is to be followed, first accept this protocol '

@interface delegatedemoviewcontroller:uiviewcontroller<updatealertdelegate>

The protocol object. Delegate = self ; //Set proxy instance

And there must be some way to implement this protocol.

-(void) Updatealert {//method of implementing the Protocol


That is, when [self . Delegate Updatealert] is in the Protocol class; The execution of this code is followed by the Protocol method implemented within the class that follows this protocol.

It's a bit of a detour, but the truth is, hahaha, just understand that when you want to use it, you write it.

Use of agents in IOS OC

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.