iosuiresponderuicontrolevents

UIResponder and multiple UIControlEvents


Is there a way to call a selector for multiple UIControlEvents?

this doesn't work, but itl'll give u an idea of what i'm trying to do.

[self.slider addTarget:self action:@selector(sliderDidStopDragging:) forControlEvents:UIControlEventTouchUpInside, UIControlEventTouchUpOutside];

thanks!!


Solution

  • try this way instead:

    // same selector for different events
    [self.button addTarget:self action:@selector(selector0:) forControlEvents:UIControlEventTouchUpInside];
    [self.button addTarget:self action:@selector(selector0:) forControlEvents:UIControlEventTouchUpOutside];
    // etc...
    

    or you can use this one:

    // different selectors for same event
    [self.button addTarget:self action:@selector(selector1:) forControlEvents:UIControlEventTouchUpInside];
    [self.button addTarget:self action:@selector(selector2:) forControlEvents:UIControlEventTouchUpInside];
    // etc...