[Stanford] MVC Introduction

Source: Internet
Author: User

The following is a lecture in the process of notes, only for the next review, found that the mistake is now changed.

1. What is MVC?

(1) Model: If the aircraft in the game, space in the spacecraft, what model, how many machine guns per ship, how many armor, these hardware components are Model.

(2) Controller: Controls how the model is presented to user on the UI. The controller's job is to communicate the model information to the view, responding to all the delegation, because it can get the data in the model and decide how to display it on the screen, which is its function.

(3) View:view is a very common tool used by controller, should be as far as possible to make the object in the View camp generalized. View is not the owner of the data it displays, and view is just a flat surface for displaying data, which is a platform for displaying information. View has no entity variables and is not stored, only pointers to them. The view is generic to display. Controller uses these generic view to do what the model needs to do.

View does not have the data it displays, how does it get the data? A delegation-like approach that has some protocols, such as data at and Count,view, that are very efficient (such as having 10,000 songs on the ipad, but only 7 on the screen), as needed. Similarly, the view will have a data source setting and the controller will respond to the data source. Note that the proxy delegation for the data source will always be the controller, or the third party specified by the controller, but not the model.

2. Ways to communicate with MVC

(1) The controller is used to display the model on the screen, so the controller has full access to the model.

(2) controller can directly with the view dialog, such as: Set the logo, let the view do something, arrange the view on the screen, data communication. Outlet is the property that the controller uses to communicate with the view, so we will create the outlets in the controller to upload to the view.

(3) Model never and view communication.

(4) View-to-controller communication is not visible, view does not know who is talking to (Controller control how to show the model on the screen)

(5) View-to-controller communication method

A) The method of the structure,target action, the controller draws a target himself, and then gives an action to its view, when the view takes action event, such as the button is pressed, It will send the action to target and the controller will know that the button is pressed. The view will report what happened to the controller, but the view does not know much about the controller but simply sends the target action.

b)delegation is another method of communication between view and controller. The view tells the Controller (did, would, should) that the controller sets himself up as a delegate, sets up a protocol, and goes back and forth (would, did, should), and the view does not know which class the controller is responding to.

(6) broadcasting . The model cannot tell the controller how to change the controller if the data in the model changes. Our approach in iOS is to use a radio station, like the information broadcast mechanism, with 2 mechanisms: notification (Notification) and critical data snooping (KVO). KVO can also be used for view and controller but not for view and Model,view no model-oriented broadcasts, and the view and controller will broadcast to each other.

The model broadcast is very useful because it is not visible, but there are restrictions that can only notify the object that is allowed to notify what happened.

(7) 1 model only 1 controllers.

Can a controller have a view conversation with someone else? Normally the controller will have a pointer pointing to another controller as the view, which will require the controller to display the object. So, when a controller needs to display complex things, it needs other controllers.

[Stanford] MVC Introduction

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.