gpt4 book ai didi

ios - 根据另一个 uiswitch 的状态更改 uiswitch

转载 作者:行者123 更新时间:2023-11-28 20:04:08 28 4
gpt4 key购买 nike

我基本上有两个切换按钮,我希望用户从两个播放器或组播放中进行选择。但是,我不希望用户能够在用户单击其中一个时理想地选择这两个,而另一个则关闭。如何最好地实现这一点?

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


[defaults synchronize];
}

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

[defaults synchronize];
}

最佳答案

你有两个开关的引用资料吗?如果是,它将是这样的:

-(void)stateSwitchedtwoplayer:(id)sender {
UISwitch *tswitch = (UISwitch *)sender;
self.switchGroup.on =! tswitch.isOn; //reference to group switch
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;
self.switchTwoPlayer.on =! tswitch.isOn; //reference to two players switch
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
[defaults setBool: tswitch.isOn forKey:@"groupswitch"];
[defaults setBool: tswitch.isOn forKey:@"twoplayerswitch"];
[defaults synchronize];
}

但是如果你希望两个开关都可以关闭,那么你只需要将它打开

self.switchGroup.on =! tswitch.isOn == YES; //reference to group switch
self.switchTwoPlayer.on =! tswitch.isOn == YES; //reference to two players switch

关于ios - 根据另一个 uiswitch 的状态更改 uiswitch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22675088/

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