2012-12-06 1 views
5

valueChanged 이벤트를 통해 IBAction에 연결되는 UISwitches 쌍이 있습니다. 스위치를 터치하면 valueChanged 이벤트가 발생합니다. 그러나 스위치 중 하나를 프로그래밍 방식으로 변경하면 IBAction이 호출되지 않습니다.프로그래밍 방식으로 변경되면 UISwitch가 valueChanged 이벤트를 보내지 않음

- (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; 
     } 
    } 
} 

답변

7

이것은 올바르지 만 원하는 동작입니다. 명시 적으로 값을 변경 했으므로 변경된 값을 처리하는 방법은 사용자가 결정해야합니다.

사용자 상호 작용을 통해 값이 변경되었다는 알림을받은 후 컨트롤의 값을 명시 적으로 변경하는 것이 일반적이지 않기 때문입니다. 명시 적 상태 변경으로 인해 이벤트가 다시 시작되면 무한 루프가 발생합니다.

관련 문제