0

i want to pass from a view controller 4 BOOL Values to my ChooseLevelVC:

if (_moves >=4) {
    clvc.level1Completed3 = 1;
}
if (_moves == 3) {
    clvc.level1Completed2 = 1;
}
if (_moves == 2) {
    clvc.level1Completed1 = 1;
} else
    clvc.level1Completed = 1;

But i don't want to present ChooseLevelVC. It should work in Background. This Bool Values changes the Image of Buttons in ChooseLevelVC.

My Code works fine if i present ChooseLevelVC with:

ChooseLevelViewController *clvc = [self.storyboard instantiateViewControllerWithIdentifier:@"chooseLevelViewController"];
if (_moves >=4) {
   clvc.level1Completed3 = 1;
}
if (_moves == 3) {
    clvc.level1Completed2 = 1;
}
if (_moves == 2) {
    clvc.level1Completed1 = 1;
 } else
    clvc.level1Completed = 1;
[self presentViewController:clvc animated:NO completion:^(){

 }];

if i don't present ChooseLevelVC, nothing happens. Do i have to save the Values? When yes, how?

thanks!

Leo
  • 24,596
  • 11
  • 71
  • 92
Sausagesalad
  • 91
  • 10

1 Answers1

0

You'll need to store your ChooseLevelViewController in a local property:

@property (nonatomic, strong) ChooseLevelViewController *chooseLevelViewController;

... so that you can instantiate it once in viewDidLoad:

- (void)viewDidLoad{
    [super viewDidLoad];

    // This is the only place you need to instantiate this view controller!
    self.chooseLevelViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"chooseLevelViewController"];
}

... and then configure it as needed:

self.chooseLevelViewController.level1Completed1 = 1;

... eventually presenting it whenever you like:

[self presentViewController: self.chooseLevelViewController animated:NO];
johnpatrickmorgan
  • 2,372
  • 2
  • 13
  • 17
  • i made this, but i don't want to [self presentViewController: self.chooseLevelViewController animated:NO]; in the active VC. its the end of a level. then i want to send level1Completed1 = 1 for example. but i don't want to present the ChooseLevelVC, im going forward to next Level. If i want to see my level progress, then i open the ChooseLevelVC in game to see, how many levels I've done yet. – Sausagesalad Jun 09 '15 at 09:23
  • Are you saying that you don't want to present the `chooseLevelViewController` from the view controller that has the data to configure it, but from a different view controller? If so, what you really want is to pass the level completion data between two view controllers. See [this answer](http://stackoverflow.com/a/29846611/3160849) – johnpatrickmorgan Jun 09 '15 at 09:58