MVC Design Patterns in iOS

Source: Internet
Author: User

First, the concept of MVC

The full name of MVC is the Model View controller, which is the abbreviation for Models-View-controller, a software design paradigm. The purpose of MVC is to separate the implementation code for M and v so that the same program can use different representations. C exists to ensure the synchronization of M and V, and once M is changed, V should be updated synchronously.

Ii. Inter-MVC communication

1, model and view can never communicate with each other, can only be passed through the controller.

2, controller can directly with the model dialogue (read and write call model), model through the notification and KVO mechanism and the controller to communicate indirectly.

3, controller can directly with the view dialog (through outlet, direct operation View,outlet directly to the control in the view), view through action to the controller to report the occurrence of events (such as the user Touch me). The controller is the direct data source of the view (the data is most likely the controller obtained from model). View can communicate with the controller via delegate.

Below, based on the MVC of iOS, add:

1. In the illustration, the green arrow indicates a direct reference. The direct reference to view is reflected in the Iboutlet. When referencing a view, such as a button. Need to be in Viewcontroller

The declaration of a Iboutlet UIButton * BTN;

2. Then, let's see how the view communicates to the Controller. For this, IOS has three common patterns:

Sets the action Target for the view. If you set UIButton's touch up inside action Target.

Set the delegate of the view, such as uialertviewdelegate, uiactionsheetdelegate,uitextfielddelegate, etc.

Set the data source for the view, such as Uitableviewdatasource.

With the above three modes, view can communicate with the controller without needing to know who the controller is, so the view is decoupled from the controller.

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.