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.

the model object model object encapsulates the application's data and defines 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 View objects are objects that users in your application can see. 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.

Controller object The Controller object acts as a medium between one or more view objects and one or more model objects in the 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. The
    2. 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
    3. controller can directly manipulate View,outlet directly to the control in the view through outlet, directly to the view dialog, and the view reports the event to the Controller via action (such as the 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.

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

Understanding the MVC design pattern in iOS for iOS development

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.