Introduction to iOS MVC learning basics

Source: Internet
Author: User

I wanted to write an article on this topic by myself, but I saw it on the Internet, so I will repost it for your reference.

Original post address: http://blog.chinabyte.com/a/1557371.html

IOS MVCThe learning base is the content to be introduced in this article. Let's take a look at the content first. Believe meMVC(Model-View-Controller) Everyone is familiar with it. InIOSUnder developmentMVCAnd I thinkIOSWrite programs on, fully understandIOSOfMVCThe pattern helps the organization of our program to be rational. On the contrary, we do not complyMVCSome of the conventions, the program can be written, but it is waiting for suffering.

Below I will only list one table for some conventions, and let's talk about it.IOSTo share with you the following information:

1. The model cannot deal with the Controller or view. That is, the model does not know who will use it. The model cannot have any reference to the Controller or view. The so-called: Don't call me, I will call you. It is designed for the model.

Let's think about it. In general programs, the model is used everywhere, and it is really difficult to maintain who uses it. Then you will ask: Bro, when the data of the model changes, how can I notify the view update? The common mechanism here is the broadcast mode, the radio mode, or the event mechanism. InIOSThere are two supported mechanisms: Notification and KVO (key-value observing ).

These two things are similar in principle, KVO isIOSA core concept in a simple understanding is that objects that focus on a data (key) of the model can be registered as listeners. Once the value of a key of the model changes, it will be broadcast to all listeners. This is the same as binding in flex and javafx.

2. view cannot directly reference the controller and model. It is controlled by the Controller to display data and receive user interaction. We know that data is required when the view is displayed, and we also know that events will occur on The View. If you want to deal with a model directly instead of a controller, you need a mechanism to support it.

InObjective-CThere is something about protocol, and the delegate (proxy mode) is proposed to solve the problem of loose interaction between uiview and controller. In addition to this,IOSThe action-Target mode is also provided to allow the Controller to listen to view events. How to obtain data from the view,IOSThis section introduces the concept of data source, which is actually a Protocol application.

3. Each operation screen pushed to the user, preferablyMVCDo not have more than one groupMVCCombination.

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.