0

ユーザーがセグメントの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 つは白の背景です。両方のストーリーボードのメイン メニューに、色を変更するオプションを備えたセグメント化されたコントロールがあります。白い背景を使用してアプリを閉じ、後でアプリを再度開いて、選択したオプションを (セグメント化されたコントロールを使用して) 表示したいとします。お役に立てれば。ありがとう!

4

2 に答える 2

0

あなたが何をしているのかわかりません... 2 つの異なる絵コンテかそれに類するものがあるようです。しかし、UISegmentedControl の 2 番目のセグメントを選択したいだけですか?

次に、1 つのビュー コントローラーを使用して、ストーリーボードを 1 つだけ持つだけです。UISegmentedControl のアウトレットにリンクしてから、mySegmentedControl.selectedSegmentIndex = 0 // Or 1... を設定しますか?

非常に単純なことをしようとしているようですが、そのために巨大なものを使用しています。

EDIT の後に EDIT :

じゃあこうして、

- (IBAction)ChangeLook:(id)sender {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    if ([defaults valueForKey:@"whiteBackground"] == 1) {
    ...// Use white storyboard
    }
    else {
    ...// Use normal storyboard
    }
}
于 2013-09-30T13:30:45.023 に答える