I have an iOS application running and I'm trying to clear part of the code structure and implementation. I would like to clarify my understanding of MVC and improve my code.
Question: is it possible to pass the model to UIView so that the view can display it based on the states of the model elements?
I will describe the example below, but I understand that it may be unclear, too tedious to read, etc. The bottom line is that if the UIView does not change any values ββin the model, is it normal that it maintains a weak reference to the model? (say, compared to what I always asked my delegate to return a temporary pointer to the model).
- thanks for any comments!
Example: Imagine a UIView, which is a 10-story CONSTRUCTION with 1 WINDOW on each floor. The MODEL for this is an NSArray containing 10 instances of custom WINDOW objects. Every WINDOW obj. has a state (light on / off) and CGRect representing the position of the WINDOW in the rectangular rectangle of the building.
The BUILDING instance controller determines the size of the building view (its frame) and all WINDOW objects, including CGRects, state, etc., creating an NSArray MODEL. Then I assign this UIView MODEL to the BUILDING controller (but save it as a strong BUILDING controller property).
UIView needs to know the state of WINDOW and CGRect in order to draw a view in drawRect .
I think that I could store CGRs separately, since they are not abstract data, but it was easier to pack all this into a single array of objects.
source share