Understanding MVC pattern used in iOS apps

后端 未结 5 1137
隐瞒了意图╮
隐瞒了意图╮ 2021-01-30 11:41

I have read Apple\'s MVC article and am confused about various things. Firstly Apple uses a combination of the View and the Controller in almost all its sample applications whi

相关标签:
5条回答
  • 2021-01-30 12:02
    • The model is the brain of the application. It does the calculations and creates a virtual world for itself that can live without the views and controllers. In other words, think of a model as a virtual copy of your application, without a face!

    • A view is the window through which your users interact with your application. It displays what’s inside the model most of the time, but in addition to that, it accepts users’ interactions. Any interaction between the user and your application is sent to a view, which then can be captured by a view controller and sent to the model.

    • Controllers in iOS programming usually refer to view controllers. Think of view controllers as a bridge between the model and your views. They interpret what is happening on one side (what the user does on the view side, or the information provided by the model) and use that information to alter the other side as needed.

    0 讨论(0)
  • 2021-01-30 12:04

    I believe that the following code will help you understand how to work with MVC in iOS application because its description says:

    "MVCNetworking is a sample that shows how to create a network application using the Model-View-Controller design pattern. Specifically, it displays a photo gallery by getting the gallery's XML description, thumbnails and photos from a web server, and uses Core Data to cache this information locally."

    http://developer.apple.com/library/ios/#samplecode/MVCNetworking/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010443

    0 讨论(0)
  • 2021-01-30 12:04

    This is by far the best, yet simple explanation I've come across(taken from RayWenderlich)

    "The idea behind MVC is that
    - VIEWS should only care about how they are presented HOW THEY ARE PRESENTED,
    - MODELS should only care about their DATA,
    - and CONTROLLERS should work to MARRY the two WITHOUT necessarily knowing too much about their internal structure."

    0 讨论(0)
  • 2021-01-30 12:13

    This sample code demonstrates a multi-stage approach to loading and displaying a UITableView. I think it's really interesting to dive in. It will show MVC in the works.

    0 讨论(0)
  • 2021-01-30 12:15

    Here’s how the Model-View-Controller (also known as MVC) pattern maps to the main parts of your App:

    Model → Data

    View → User Interface

    Controller → Core Logic

    this explain fully with sample code

    http://www.hollance.com/2011/04/making-your-classes-talk-to-each-other-part-1/

    enter image description here

    0 讨论(0)
提交回复
热议问题