0

I have a view controller placeViewController which pulls in a bunch of Place objects, and from these loads and populates a matching bunch of PlaceView objects which are then displayed as subviews to its main view.

I need to update these views periodically which requires information from the model and other places to be pushed into the views

How should I properly structure this?

  • Keep an array of Place objects and give the model a PlaceView property to store pointers to the views

  • Keep an array of PlaceView objects and give the view a Place property to store pointers to the places

  • Keep both arrays and use a lot of indexOfObject objectAtIndex to jump between them

  • Some other way??

trapper
  • 11,716
  • 7
  • 38
  • 82
  • I would create a `NSMutableArray` with `PlaceView` objects. And the `PlaceView` class holds a `@property Place *place` – basvk Oct 29 '12 at 08:26
  • basvk, I think this is the best approach and it is what i ended up doing. If you want to post as an answer I will mark it correct. – trapper Nov 06 '12 at 03:14

2 Answers2

0

I need to update these views periodically which requires information from the model and other places to be pushed into the views

You should really focus on an ObserverPattern. Yours views register to "notifications", and when changes are made, your registered views are notified.

http://en.wikipedia.org/wiki/Observer_pattern

You still can use NSNotificationCenter, but it will not futfill your needs since you need yours views make update per Place object (paired like a dictionary). So i recommend you to implement your own. It will loose coupled because your controller will just only make glue between the observer and your views, and all the "logic" will be handled by the observer.

Mr Bonjour
  • 3,330
  • 2
  • 23
  • 46
0

Well basvk got the answer in his comment but hasn't posted an actual answer for me to mark correct.

So here it is: "I would create a NSMutableArray with PlaceView objects. And the PlaceView class holds a @property Place *place"

trapper
  • 11,716
  • 7
  • 38
  • 82