Model-view-controller (The IPhone Developer ' s Cookbook)

Source: Internet
Author: User

Model-view-controller

MVC separates the onscreen object looks from the IT behaves. A onscreen button (the view) has no intrinsic meaning. It ' s just a button that users can push. That view ' s controller acts as an intermediary. It connects user interactions such as button taps to targeted methods in your application, which is the model. The application supplies and stores meaningful data and responds to interactions such as these button taps by producing so Me sort of useful result.

Each MVC element works separately. You might swap out a push button with, for example, a toggle switch without changing your model or controller. The program con-tinues to work as before, and the GUI now have a different look. Alternatively, you might leave the interface as are and change your application where a button triggers a different kind of Response in your model. Separating these elements enables the build Main-tainable program, the can be updated independently.

The MVC paradigm on the IPhone breaks to the following categories:

@ View. View components is provided by children of the UIView class and by its associated (and somewhat misnamed) Uiviewcontrolle R class.

@Controller. The controller behavior is implemented through three key technolo-gies:delegation, target-action, and notification.

@Model. Model methods supply data through protocols such as data sourcing and meaning by implementing callback methods triggered B Y the controller.

Together these three elements form the backbone of the MVC programming Para-digm. Let's look at all of these elements of the IPhone MVC design pattern in a bit more detail. The following sections introduce each element and its supporting classes.

Model-view-controller

MVC separates the object that is displayed on the screen and its behavior. A button on the screen (view) has no practical meaning, it's just a button that a user can click. The view's controller (the controllers of the views) plays an intermediary role. Model connects user interaction, such as clicking the button in your program to the target method. The application provides and stores meaningful data and responds to user interactions such as a series of user data generated by a button click.

Every element of MVC works separately. You can replace the push button with a toggle switch without changing your model and controller. The program still runs the same way as before, but there are some different things that appear in the interface. Or you can change the response of the button in your program without changing the interface. Separating these elements allows you to create a maintainable, rapidly updated program element.

The MVC example class in the iphone:

The @ View view element is provided by the UIView class and its associated Uiviewcontroler classes and their subclasses.

The implementation of @Conreoller controller behavior is through three key technologies: Delegation,target-action,notification.

The @Model Model method provides data through protocols, such as providing the data source and meaning by implementing a callback method triggered by the controller.

Model-view-controller (The IPhone Developer ' s Cookbook)

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.