0

I am trying to represent the same data in two different ways, one in TableView, one in map. The storyboard design looks like below.

storyboard

I used two container views; one contains a table view and one contains a map. Let's call the ViewController that has segmented control as SegView. In the SegView controller - viewDidLoad method, I get the data from server and want both tableview and map use this data.

However, since the tableview, the map, and the SegView have three different ViewController instances, I am wondering how to pass the data from SegView to the two container view. Could you help me on that?

Paulw11
  • 108,386
  • 14
  • 159
  • 186
J. zhao
  • 43
  • 1
  • 7

1 Answers1

1

If you look at your storyboard you will see that there are segues linking SegView to your contained view controllers; these are the embed segues that are used to load the two contained views.

You can click on these segues in the storyboard and give them an identifier just like any other.

Once you have given them identifiers, you can identify these segues in the prepareFor(segue:) function in SegView and get the reference to the contained ViewController using the segue.destination property.

Paulw11
  • 108,386
  • 14
  • 159
  • 186