3

I have a UISwitch element which shows a alert view controller on toggle.

UISwitch *element = [[UISwitch alloc] initWithFrame:CGRectZero];
[element addTarget:self action:@selector(doSomething:) forControlEvents:UIControlEventValueChanged];  

-(void)doSomething:(UISwitch *)switch
  {
    // show alert view controller
  }

After switching the toggle, if I hold on to the UISwitch control and not release my fingers, even though the alert view is been shown, I'm still able to switch between ON and OFF. Is there any way we can relinquish control of the UISwitch element while the user hasn't released his finger yet. I'd like to give up control of the switch on receiving the first UIControlEventValueChanged event?

harshith__
  • 447
  • 3
  • 15
  • Have you tried `[element setUserInteractionEnabled:NO];` after the first `UIControlEventValueChanged` event? I haven't tested so I can't confirm, but its summary says `A Boolean value that determines whether user events are ignored and removed from the event queue`, so it's possible it will stop sending events at that point. – Jake G Dec 03 '18 at 19:31
  • 1
    Yes @JakeG , I did try that. Did not work though. I'm guessing that's because the user is still holding onto the element. – harshith__ Dec 04 '18 at 04:27

0 Answers0