0

i have a game that contain two viewcontroller, when the user end the game in viewcontrollerA his score is passing to viewcontrollerB that check if the user correct score is bigger that the high score and if it does the high score change to the user correct score. now, i succeeded to passing my var value forward but now i want to show the high score in a label on viewControllerA. i tried to use a @property(like i do to pass the correct score to viewcontrollerB) but i didn't succeeded. how can i do it?

user1492776
  • 280
  • 2
  • 7
  • 14
  • possible duplicate of [passing data back to a previously allocated UIViewController](http://stackoverflow.com/questions/6941474/passing-data-back-to-a-previously-allocated-uiviewcontroller) or http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers or http://stackoverflow.com/questions/8697255/implementing-a-delegate-to-enable-a-modal-view-to-pass-data-back-to-a-uiviewcont – jscs Jul 11 '12 at 17:33

1 Answers1

1

I'd say what you are really looking for is NSUserDefaults.

You use it to store Data persistently, across ViewControllers and even across App-Restarts. For example what you do is:

    [[NSUserDefaults standardUserDefaults] setInteger:highScore forKey:@"CurrentHighscore"];

to store a value. And once you want to read it (maybe after the app is restarted, in the viewDidLoad method of some viewcontroller, you would do:

    UILabel* someUILabel;
someUILabel.text = [NSString stringWithFormat:@"Highscore: %i", [[NSUserDefaults standardUserDefaults] integerForKey:@"CurrentHighscore"]];
Bersaelor
  • 2,517
  • 34
  • 58