Friday, May 6, 2011

Can someone show me a diagram of how view controllers work?

Can someone show me a diagram of how view controllers work in cocoa (obj-c).

I just want to understand because they are confusing me

Thanks!

From stackoverflow
  • I don't think a UIViewController can be summed up in a diagram.

    What specifically is it that you are having difficulty with? The navigation from one controller to another? The stacking aspect of a NavigationController? Or the structure of your look and feel inside a ViewController?

    The question is so open ended, I don't think it can be answered in a single thread on this site. I would point you toward Lecture 6 of the Stanford class on iPhone programming. Both the lecture notes and the lecture itself (with sample exercises) can be found at: http://www.stanford.edu/class/cs193p/cgi-bin/index.php

    Daniel Kindler : thanks, I'll watch that video. But I'm just having trouble understanding what is it that the view-controller does?
    danielpunkass : Agree with mmc. You should try to seek out more broad-spectrum explanations of iPhone programming in general, then return with a more specific question if you still don't understand.
  • The stanford link is a great reference.

    Generally, a view controller provides the "glue" to your application. It should get/process the data from your Model(s) and hand it off to the view. Almost all of the application logic will be in the View Controller.

    The following text is from the Cocoa Fundamentals Guide by Apple:

    Controller Objects Tie the Model to the View

    A controller object acts as the intermediary between the application's view objects and its model objects. Controllers are often in charge of making sure the views have access to the model objects they need to display and act as the conduit through which views learn about changes to the model. Controller objects can also perform set-up and coordinating tasks for an application and manage the life cycles of other objects.

    In a typical Cocoa MVC design, when users enter a value or indicate a choice through a view object, that value or choice is communicated to a controller object. The controller object might interpret the user input in some application-specific way and then either may tell a model object what to do with this input—for example, "add a new value" or "delete the current record"; or it may have the model object reflect a changed value in one of its properties. Based on this same user input, some controller objects might also tell a view object to change an aspect of its appearance or behavior, such as disabling a button. Conversely, when a model object changes—say, a new data source is accessed—the model object usually communicates that change to a controller object, which then requests one or more view objects to update themselves accordingly.

    Controller objects can be either reusable or non-reusable, depending on their general type. “Types of Cocoa Controller Objects” describes the different types of controller objects in Cocoa.

    A relevant diagram would be the relationship between the Model,View, and the Controller (again courtesy of apple):

    MVC Diagram

    Daniel Kindler : thanks man! that waas a help

0 comments:

Post a Comment