我希望能够让用户选择其中一个段,并且当他们加载该视图控制器备份时,他们选择的那个将被选中。默认情况下,我选择了“黑色”,但如果他们选择“白色”然后关闭他们的应用程序,重新打开它“然后将选择白色。
这是我为第一个情节提要的分段控制器的代码:
- (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");
}
}
这是第二个故事板的分段控制器的代码:
- (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");
}
}
我也可能有一件可能有帮助的:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[NSNumber numberWithInt:[backgroundColour selectedSegmentIndex]] forKey:@"whiteBackground"];
我知道这不会保存或加载它,但它可能会帮助有人帮助我回答。所以我需要保存为两个视图控制器选择的选项。
* 编辑 *
我有这个游戏,我希望它与用户的设备颜色匹配,或者只是为了提供更多选择。所以我有两个故事板,一个是黑色背景,一个是白色背景。在两个故事板中,在主菜单中,我有一个分段控件,可以选择更改颜色。假设我想要白色背景,然后关闭应用程序,然后再打开它,我希望他们选择的选项出现(使用分段控件)。希望这可以帮助。谢谢!