0

Is there a way to send data between ViewControllers without using segues?

Specifically I have two ViewControllers embedded in a TabBarViewController. One is called PlayingCardViewController and the other is called HighScoreViewController. I want to pass a class HighScore from PlayingCardViewController to HighScoreViewController. I want to transfer the data from PlayingCardViewController as soon as I press the redeal button in PlayingCardViewController but I don't want to transition to the HighScoreViewController as that would be jarring for the player.

I thought about using segues and holding the HighScores in an array and passing that to all the VC's that PlayingCardViewController is connected to but I realized that that seems overly complicated and there must be a simpler way to pass the data upon hitting the redeal button.

Some relevant links Passing Data between View Controllers

Community
  • 1
  • 1
MichaelGofron
  • 1,310
  • 4
  • 15
  • 29
  • possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – Lithu T.V Sep 05 '14 at 16:14
  • That "relevent" Question is enough to answer everything about this.What more do you expect? – Lithu T.V Sep 05 '14 at 16:15
  • That question involves passing data using segues, whereas I don't want to pass my data through a segue – MichaelGofron Sep 05 '14 at 16:27

1 Answers1

1

I'm just going to do this with bullet points:

  • You could implement a custom tab bar controller (your own UITabBarController subclass), and use this instead of a basic UITabBarController.
  • Your PlayingCardViewController could have its own delegate protocol/property.
  • The delegate protocol could define a method like playingCardVC:didSetHighScore:.
  • Your tab bar controller would be the PlayingCardViewController's delegate.
  • The tab bar controller could keep a reference to the HighScoreViewController.
  • When your tab bar controller gets the playingCardVC:didSetHighScore:, it could pass whatever you want to your HighScoreViewController.
JoeFryer
  • 2,751
  • 1
  • 18
  • 23