ユーザーがセグメントの1つを選択できるようにしたいのですが、そのビューコントローラーをロードすると、選択したセグメントが選択されます。デフォルトでは「黒」が選択されていますが、「白」を選択してアプリを閉じた場合、アプリを再度開くと「白が選択されます。
最初のストーリーボードのセグメント化されたコントローラーのコードは次のとおりです。
- (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");
}
}
2 番目のストーリーボードのセグメント化されたコントローラーのコードは次のとおりです。
- (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");
}
}
私はまた、おそらく役立つかもしれない1つのピースを持っています:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[NSNumber numberWithInt:[backgroundColour selectedSegmentIndex]] forKey:@"whiteBackground"];
これが保存またはロードされないことはわかっていますが、誰かが答えを手伝ってくれるかもしれません。したがって、両方のビュー コントローラーで選択したオプションを保存する必要があります。
* 編集 *
私はこのゲームを持っており、ユーザーのデバイスに合わせて色を合わせたり、より多くの選択肢を提供したりしたいと考えています。したがって、2 つのストーリーボードがあり、1 つは黒の背景、もう 1 つは白の背景です。両方のストーリーボードのメイン メニューに、色を変更するオプションを備えたセグメント化されたコントロールがあります。白い背景を使用してアプリを閉じ、後でアプリを再度開いて、選択したオプションを (セグメント化されたコントロールを使用して) 表示したいとします。お役に立てれば。ありがとう!