我有一对通过 valueChanged 事件连接到 IBAction 的 UISwitches。触摸开关时 valueChanged 事件触发良好。但是,如果我以编程方式更改其中一个开关,它不会调用我的 IBAction。
- (IBAction)switchChanged:(UISwitch *)sender {
if (sender == self.shippingSwitch) {
if (self.shippingSwitch.on && !self.PayPalSwitch.on) {
[self.PayPalSwitch setOn:YES animated:YES];
}
}
if (sender == self.PayPalSwitch) {
if (!self.PayPalSwitch.on) {
// This is not working when the PayPal switch is set via the code above
self.PayPalEmailField.backgroundColor = [UIColor grayColor];
self.PayPalEmailField.enabled = NO;
if (self.shippingSwitch.on) {
[self.shippingSwitch setOn:NO animated:YES];
}
} else {
self.PayPalEmailField.backgroundColor = [UIColor clearColor];
self.PayPalEmailField.enabled = YES;
}
}
}