Note that there are some explanatory texts on larger screens.

plurals
  1. POSave and load state of Segmented Controler
    primarykey
    data
    text
    <p>I want to be able to have the user to select one of the segments and when they load that viewcontroller back up, the one they chose will be select. At default I have "Black" Selected but if they choose "White" and then close they app, reopen it "White will then be selected.</p> <p>Here is the code I have for the Segmented Controller for the first storyboard:</p> <pre><code>- (IBAction)ChangeLook:(id)sender { if (backgroundColour.selectedSegmentIndex == 0) { UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"iPhoneStoryboard4inch-White" bundle: nil]; MainMenuView_4inch_White *second = [mainStoryboard instantiateViewControllerWithIdentifier:@"MainMenuView_4inch-White"]; [self presentViewController:second animated:NO completion:nil]; NSLog(@"White Selected"); } if (backgroundColour.selectedSegmentIndex == 1) { UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"iPhoneStoryboard4inch" bundle: nil]; MainMenuView_4inch *second = [mainStoryboard instantiateViewControllerWithIdentifier:@"MainMenuView_4inch"]; [self presentViewController:second animated:NO completion:nil]; NSLog(@"Black Selected"); } } </code></pre> <p>Here is the code I have for the Segmented Controller for the second storyboard:</p> <pre><code>- (IBAction)ChangeLook:(id)sender { if (backgroundColour.selectedSegmentIndex == 0) { UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"iPhoneStoryboard4inch-White" bundle: nil]; MainMenuView_4inch_White *second = [mainStoryboard instantiateViewControllerWithIdentifier:@"MainMenuView_4inch-White"]; [self presentViewController:second animated:NO completion:nil]; NSLog(@"White Selected"); } if (backgroundColour.selectedSegmentIndex == 1) { UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"iPhoneStoryboard4inch" bundle: nil]; MainMenuView_4inch *second = [mainStoryboard instantiateViewControllerWithIdentifier:@"MainMenuView_4inch"]; [self presentViewController:second animated:NO completion:nil]; NSLog(@"Black Selected"); } } </code></pre> <p>I also have possibly one piece that might help :</p> <pre><code>NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:[NSNumber numberWithInt:[backgroundColour selectedSegmentIndex]] forKey:@"whiteBackground"]; </code></pre> <p>I know this doesn't save or load it but it may help someone help me with the answer. So I need to save the option chosen for both view controllers. </p> <p><strong>* EDIT *</strong></p> <p>I have this game and I want it to colour match the user's device or just for more choice. So I have two storyboards, one with the black background and one with the white background. In both storyboard, in the main menu I have a Segmented Control with the option to change the colour. Let's say I want to have the white background then close the app and later on open it back up, I want the option they selected to appear (using the segmented control). Hope this helps. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload