- We send a message to the object to initiate a specific action. When the object sends some changes, it notifies us through the callback function. When a specific event occurs, the object calls the corresponding callback function to trigger the business logic.
- The callback function is implemented through the so-called delegation.
Delegate ------- benefits:
It separates the logic processing of the program from the uiapplication more concisely.
It avoids programmers from directly deriving subclasses from uiapplication. Imagine how painful it is to manage the lifecycle and system events of an application by deriving subclasses from uiapplication.
In the "delegate mode", two objects are generally involved in processing the same request. The so-called request in the iPhone is the application's lifecycle and system events, the object that receives the request delegates the request to another object for processing. In the same iPhone, The uiapplication delegates the request to uiapplicationdelegate after receiving the lifecycle and system events.
The reason why the iPhone does not use the inheritance system but uses the delegated mode for aggregation is that the iPhone framework is diversified, which makes inheritance unable to ensure the consistency of sub-class behaviors, the delegated mode is precisely designed to make up for the disadvantages of inheritance.
Each project has a uiapplication object to process the lifecycle and system events of the application. The main () function initializes the uiapplication of the application through uiapplicationmain, if you want to operate the uiapplication of an application, you can only use [uiapplication sharedapplication] To obtain the reference of the uiapplication. This method returns a globally unique uiapplication object to the reader.
Likewise, you can use the following code to obtain the application's delegate object: uiapplicationdelegate * mydelegate = [[uiapplication sharedapplication] Delegate];
Protocol:
Object-C does not have many inheritance. So we need to avoid making an object that can be used in any way (super class monster, huge
, Super, waste) a super object itself denies the concept and meaning of object-oriented. To make the code more concise and organized, you can separate some of the duties.
The Protocol itself has no specific implementation. Only some interfaces that can be implemented by other classes are specified.
Delegate is always defined as assign @ Property
- @ Interface uitextfield
- @ Property (assign) ID <uitextfielddelegate> delegate;
- @ End