-1

i recently started ios development and am kind of stuck here. I created an tabbed application. Inside the FirstViewController i hold a list of objects, containing coordinates. On the second tab I have a MapView.

I want to show a pin on the map for every coordinate in the list in ViewController 1 but I don't know how

  1. I can access the Array in the other viewController
  2. I can get informed when this list grows so the additional pins can be created
StefanG
  • 239
  • 3
  • 12
  • You should think about "modeling" your point data into some sort of structure that is accessible to both view controllers that need to know about it. This is a very common question. – Aaron Mar 11 '15 at 16:46

2 Answers2

0

You should read about MVC or MVVM. In this design patterns you should use model which store Coordinates. And Controller or ViewModel must have link to this model.

ViewControllerA -> owns CoordinateModel ViewControllerB -> owns the same CoordinateModel

Also, Coordinate model should inform both controllers about changes.

Pavel Gatilov
  • 2,570
  • 2
  • 18
  • 31
0

If the map view controller needs to know about what's happening in the first controller, but not the other way around, I would suggest using delegation. Make the map view controller the delegate of the first controller, and have that first controller send a message to its delegate any time its array of objects changes.

rdelmar
  • 103,982
  • 12
  • 207
  • 218