Model-View-Controller (MODEL-VIEW-CONTROLLER,MVC) is a software design pattern invented by Xerox PARC in the the 1980s for programming language Smalltalk-80, which has been widely used in user interaction applications. In iOS development, the MVC mechanism is used thoroughly, fully understand the iOS mvc pattern, help our program organization rationality.
Model objects
Model objects encapsulate the application's data and define the logic and operations that manipulate and manipulate the data. For example, a model object might represent a role in a game or a contact in an address book. The actions that the user creates or modifies data in the view layer are communicated through the Controller object and eventually the model object is created or updated. When a model object changes (for example, new data is received over a network connection), it notifies the controller object that the Controller object updates the corresponding View object.
View Object
A View object is an object that the user can see in the application. The View object knows how to draw itself and may respond to the user's actions. The primary purpose of a View object is to display data from an application model object and make that data editable. However, in an MVC application, the View object is usually detached from the model object.
In iOS application development, all controls, windows, and so on are inherited from UIView, corresponding to the V in MVC. UIView and its subclasses are responsible for the implementation of the UI, and the events generated by UIView can be entrusted to Uiviewcontroller.
Controller Object
A Controller object acts as a medium between one or more view objects and one or more model objects in an application. The Controller object is therefore a synchronous pipe program through which the view object understands changes to the model object, and vice versa. The Controller object can also perform settings and reconcile tasks for the application and manage the life cycle of other objects.
The Controller object interprets user actions in the View object and communicates new or changed data to the model object. When a model object changes, a controller object communicates the new model data to the View object so that the view object can display it.
For different uiview, there are corresponding uiviewcontroller, corresponding to the C in MVC. For example, the UITableView used on iOS, the controller that corresponds to it is uitableviewcontroller.
- Model and view can never communicate with each other and can only be passed through the controller.
- The controller can talk directly to the model (read and write call model), and the model communicates indirectly with the controller through the notification and KVO mechanisms.
- The controller can directly manipulate View,outlet directly to the control in the view through outlet, directly to the view, and the view reports the event to the Controller via action (such as a user touch me). The controller is the direct data source of the view (the data is most likely the controller has been obtained from the model and processed). The controller is the proxy for the view (delegate) to synchronize the view with the controller.
MVC Design Patterns in iOS