iOS Development understanding MVC Design Patterns in iOS

Source: Internet
Author: User

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.

    1. Model and view can never communicate with each other and can only be passed through the controller.
    2. 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.
    3. 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.

C to M:api
C to V:outlet
V to C:target-action, Delegate,datasource
M to C:notification,kvo

For complete information about model-view-controller, see Concepts in OBJECTIVE-C programming(Concepts in OBJECTIVE-C programming): Model-view-controller

iOS Development understanding MVC Design Patterns in iOS

Related Article

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.