3

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!!

Sean Danzeiser
  • 9,141
  • 12
  • 52
  • 90

3 Answers3

16

Just OR them:

[self.button addTarget:self action:@selector(selector0:) forControlEvents:(UIControlEventTouchUpInside|UIControlEventTouchUpOutside)];
Snowcrash
  • 80,579
  • 89
  • 266
  • 376
2

They are now an option set so you can use for: [.touchUpInside, .touchUpOutide]

Sam Woolf
  • 81
  • 7
1

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...
holex
  • 23,961
  • 7
  • 62
  • 76