Domanda

In Cocoa MVC adoption, View knows nothing about the Model, which illustrated in this diagram:

Cocoa MVC interaction diagram

But consider this example:
I have Item class in my model and I want visual representation for it. Most obvious for me is ItemView class, which is initialized with Item.
So, in this way, I'm breaking Cocoa MVC rules and feeling uncomfortable with it. But, I'm feeling uncomfortable also not having class like ItemView. What is the most practical solution?

È stato utile?

Soluzione

If you are really concerned about MVC, what about defining a method in your controller like:

- (UIView*)itemViewForItem:(Item*)item;

which is responsible for creating and "populating" your ItemView?

You main controller class would then act as a controller both for your main view and all ItemViews you have got.

Another approach would be giving each ItemView its own ItemViewController. This is perfectly fine and if your controller/view is of any complexity, IMO, also the best approach. The drawback with this is that dealing with controllers container is supported only on iOS>5.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top