0

In my application I created a container view(called ContainerViewController) on the top of an another view(called GameViewController,where I keep the game logic and api callbacks).I also have other views and an api class.My container view contains 3 views and I am trying to pass some objects to one of my container view(VC1). Since GameViewController is only connected to ContainerViewController(meaning there is no segue directly, so I can't use prepareforsegue and I can't use presentViewController, since they childViewControllers), I can't pass data. I also tried just getting the values from my deserializer class(inside vc1). The problem with that was the VC1 gets called before.

my question is, how can I set values of VC1 from my callback inside the GameViewController? This is what my storyboard looks like:enter image description here

Thank you.

Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
Matt
  • 674
  • 11
  • 25
  • 1
    Use `NSNotificationCenter` . – Toseef Khilji Dec 24 '13 at 09:25
  • Use a protocol and delegate and have a look here : http://stackoverflow.com/questions/6168919/how-do-i-set-up-a-simple-delegate-to-communicate-between-two-view-controllers If you are not familiar with notification, you will send a lot of notifications without removing the old one. – Jordan Montel Dec 24 '13 at 09:27
  • @JordanMontel, aren't we suppose to use protocol and delegate, when passing data backwards only? – Matt Dec 24 '13 at 09:30
  • It's easier. Use `property` to pass data from A to B and use `protocol` to pass data backward from B to A – Jordan Montel Dec 24 '13 at 10:07

1 Answers1

1

You can do it many ways:

1st way : You can pass the data using Notification.

2nd way : You can create a separate singleton data model class to store your game data. Then you can access the object of that class among your view controllers to set the properties in view controllers.

san
  • 3,350
  • 1
  • 28
  • 40