Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

blue-lion

macrumors member
Original poster
Jan 26, 2010
50
0
Wirelessly posted (Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3)

Hi. I have a question regarding the MVC design concept. In most diagrams I have seen ( including material from the stamford lectures) there is no allowance for data to be passed back from the model to the controller. And yet data has to be passed back in order to be passed to  a view,right?. Or maybe I'm mistaking data for communication? 

I have a private model object declared in my main controller as per recommended in the lectures ,but surely  the results have to be fed back from the model to the view via the controller?
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
In the first lecture of 2010 for the Stanford class, there was a slide showing how the data travels.

As I recall, KVO (Key-Value-Observing) is used to alert the Controller of changes in the Model, and then the Controller tells the View directly.

Then again, I suck at grasping MVC and have to ask for help regarding it all the time.
 

KnightWRX

macrumors Pentium
Jan 28, 2009
15,046
4
Quebec, Canada
The way I do it is simple. The Controller has instances of both my Model and my View classes and is responsible to be a broker of sorts between the two. The View and Model communicate back with the Controller on changes or requests for information using Objective-C protocols, the Controller being the delegate.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,745
8,419
A sea of green
Wirelessly posted (Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3)

Hi. I have a question regarding the MVC design concept. In most diagrams I have seen ( including material from the stamford lectures) there is no allowance for data to be passed back from the model to the controller. And yet data has to be passed back in order to be passed to *a view,right?. Or maybe I'm mistaking data for communication?*

I have a private model object declared in my main controller as per recommended in the lectures ,but surely *the results have to be fed back from the model to the view via the controller?

The Controller is not always a middleman.
http://en.wikipedia.org/wiki/Model–view–controller#Concepts
The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). [underline added]​
The View has a direct connection to the Model (see diagram at top of that article), so it clearly has direct access to any data objects exposed by the Model. If it's unclear, the "information about its state" means "data". There is no need for the Controller to sit between these two for this purpose.

Also see item #4 under the Overview heading of that article.

So yes, I think you are mistaking data for communication or association.

EDIT
An example of a Model object that supplies data directly to a View is UITableViewDataSource. The data-source is the Model. Or more specifically, the Model object conforms to the UITableViewDataSource protocol. There is no controller object sitting between the UITableView and its data source. There is a controller involved in the overall interaction, but it's not sitting in the data-path between the Model and View.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.