屏幕上有 6 个开关控件。一次只能启用一个开关。如果第 5 个开关打开,则一个标签和一个文本字段应该可见,或者应该隐藏。
我遇到了问题,当 5 开关从关闭变为开启并再次变为关闭时。标签和文本文件应该被隐藏,但它不能按要求工作。
- (void)viewDidLoad
{
[super viewDidLoad];
self.sw_switch1.on = NO;
self.sw_switch2.on = NO;
self.sw_switch3.on = NO;
self.sw_switch4.on = NO;
self.sw_switch5.on = NO;
self.sw_switch6.on = NO;
lbl_desc.hidden = YES;
txt_desc.hidden = YES;
}
-(IBAction)switchChange:(id)sender
{
if(sw_switch1.isOn)
{
//self.sw_switch1.on = NO;
self.sw_switch2.on = NO;
self.sw_switch3.on = NO;
self.sw_switch4.on = NO;
self.sw_switch5.on = NO;
self.sw_switch6.on = NO;
}
else if(sw_switch2.isOn)
{
self.sw_switch1.on = NO;
//self.sw_switch2.on = NO;
self.sw_switch3.on = NO;
self.sw_switch4.on = NO;
self.sw_switch5.on = NO;
self.sw_switch6.on = NO;
}
else if(sw_switch3.isOn)
{
self.sw_switch1.on = NO;
self.sw_switch2.on = NO;
//self.sw_switch3.on = NO;
self.sw_switch4.on = NO;
self.sw_switch5.on = NO;
self.sw_switch6.on = NO;
}
else if(sw_switch4.isOn)
{
self.sw_switch1.on = NO;
self.sw_switch2.on = NO;
self.sw_switch3.on = NO;
//self.sw_switch4.on = NO;
self.sw_switch5.on = NO;
self.sw_switch6.on = NO;
}
else if(sw_switch5.isOn)
{
self.sw_switch1.on = NO;
self.sw_switch2.on = NO;
self.sw_switch3.on = NO;
self.sw_switch4.on = NO;
//self.sw_switch5.on = NO;
self.sw_switch6.on = NO;
lbl_desc.hidden = YES;
txt_desc.hidden = YES;
}
else if(sw_switch6.isOn)
{
lbl_desc.hidden = NO;
txt_desc.hidden = NO;
self.sw_switch1.on = NO;
self.sw_switch2.on = NO;
self.sw_switch3.on = NO;
self.sw_switch4.on = NO;
self.sw_switch5.on = NO;
//self.sw_switch6.on = NO;
}
[self viewWillAppear:NO];
}