gpt4 book ai didi

ios - 为什么我的 uiswitch 变得困惑

转载 作者:行者123 更新时间:2023-11-29 03:06:52 24 4
gpt4 key购买 nike

我在一个 View Controller 上有 4 个 ui 开关,其中两个工作正常,但最后两个已设置,因此您只能单击任一组或两个播放器,但是当您单击两个播放器然后单击保存并返回时打开两个开关,但是如果你在组中做同样的事情,它不会这样做吗?

有人看到我在这里做错了什么吗?

   -(void)stateSwitched:(id)sender {
UISwitch *tswitch = (UISwitch *)sender;
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
[defaults setObject: tswitch.isOn ? @"YES" : @"NO" forKey:@"truthonoff"];

[defaults synchronize];
}

-(void)stateSwitcheddare:(id)sender {
UISwitch *tswitch = (UISwitch *)sender;
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
[defaults setBool: tswitch.isOn forKey:@"groupswitch"];
[defaults setBool: tswitch.isOn forKey:@"twoplayerswitch"];
[defaults synchronize];
}

-(void)stateSwitchedtwoplayer:(id)sender {
UISwitch *tswitch = (UISwitch *)sender;
//turns two player off when on and soforth

self.groupswitch.on =! tswitch.isOn;
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
[defaults setBool: tswitch.isOn forKey:@"twoplayerswitch"];
[defaults setBool: !tswitch.isOn forKey:@"groupswitch"];

[defaults synchronize];
}

-(void)stateSwitchedgroup:(id)sender {
UISwitch *tswitch = (UISwitch *)sender;
//turns two player off when on and soforth
self.twoplayerswitch.on =! tswitch.isOn;
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
[defaults setBool: tswitch.isOn forKey:@"groupswitch"];
[defaults setBool: tswitch.isOn forKey:@"twoplayerswitch"];
[defaults synchronize];
}

刚刚意识到我在 viewdidload 上运行它可能会影响它?

[self.twoplayerswitch setOn:[[defaults objectForKey:@"twoplayerswitch"] boolValue] animated:YES];

[self.twoplayerswitch addTarget:self action:@selector(stateSwitchedtwoplayer:) forControlEvents:UIControlEventValueChanged];

[self.groupswitch setOn:[[defaults objectForKey:@"groupswitch"] boolValue] animated:YES];

[self.groupswitch addTarget:self action:@selector(stateSwitchedgroup:) forControlEvents:UIControlEventValueChanged];

最佳答案

stateSwitchedtwoplayer 方法中,您可能会更改 self.groupswitch.on 的状态,但不会将更改保存到 NSUserDefaults。

关于ios - 为什么我的 uiswitch 变得困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22675447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com