views:

76

answers:

1

Another newbie question : I have a simple iPhone app with a model, a controller and a view class.

I want to draw a rectangle in the view using variables from the model (like the size or the position)

What is the best way to make reference inside the drawRect method code, to variables from the model instance ? (the model is instanciated from within the controller - as recommended in the MVC design pattern)

KVO ? KVC ? Binding ? Teleportation ?

Thanks for you help.

A: 

have your controller hold a reference to your model. In your interfrace section delcare:

MyModel *myModel;

and in your implementation you would do this:

MyModel *myModel = [[MyModel alloc] init]];

and set the model vars there

ennuikiller
Thanks. My controller is instanciating the model as you suggest.My problem comes from the fact that drawRect is a View method and the View object does not know about vars that were created in the Controller.The question is how can the drawRect method in the View be aware of what is in a model variable instanciated in the controller ?(Hope this is clear)