Mvc
Model-View-controller (MVC) design pattern
MVC divides classes by role, involving three roles:
Model: Models Save the application's data.
View: Views are visual representations of the model and controls for user interaction.
Controller: Controllers are intermediaries who coordinate all work. It accesses the data in the model and displays them in the view, while they also listen for events and manipulate data.
Single Case design mode
The singleton design pattern ensures that there is only one instance (object) for a class, and that the object has a global access point. Lazy loading is usually used to create the object the first time it is used.
How to create a single case:
Such as: Declare the class method in SortDetailsModelDown.h + (Sortdetailsmodeldown *) Sharesortdetailsmodeldown;
Implement this method in SORTDETAILSMODELDOWN.M
Static Sortdetailsmodeldown * single = nil;
+ (Sortdetailsmodeldown *) sharesortdetailsmodeldown{
@synchronized (self) {
if (!single) {
single = [[Sortdetailsmodeldown alloc]init];
}
}
return single;
}
Agent
Custom protocols:
Agents: Objects that follow the agreement
First step: Make Agreement: (Protocol Name: class name +delegate)
@class MyView; @protocol myviewdelegate <NSObject> @required//methods that must be implemented-(void) Changeviewbackgroudcolor: (MyView * ) view, @optional//optional Method-(void) test; @end
Step two: Make a proxy
@interface Myview:uiview Step Two: Specify the proxy @property (nonatomic,assign) ID Delegate ; @end
The third step: the agent follows the agreement.
The fourth step: proxy implementation of the Protocol must be implemented in the method and other optional methods.
Fifth step: The client notifies the agent to start the execution method.
Observers
KVO Key-value observing. It is a mechanism that KVO automatically notifies the appropriate observer when the properties of the specified object have been modified.
- Registered Observer
[message addObserver:self forKeyPath:kKVOPathKey options:NSKeyValueObservingOptionNew context:Nil];
- Change the value of the Theme object property, which is the notification that triggered the change sent
_message.key = @"asdfasd";
- in the developed callback function, process the received change notification
12345 6 |
-( void void *) context { &NBSP; if ([ KeyPath Isequal:kkvopathkey] && Object = = _message) { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; NSLog (@ "Get%@" ,change); &NBSP; } } |
- Logout Observer
[_message removeObserver:self forKeyPath:kKVOPathKey];
iOS common design Patterns: MVC, Singleton, Agent, observer.