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