UIResponder and multiple UIControlEvents

2019-07-19 11:54发布

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

2条回答
Bombasti
2楼-- · 2019-07-19 12:03

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...
查看更多
倾城 Initia
3楼-- · 2019-07-19 12:25

Just OR them:

[self.button addTarget:self action:@selector(selector0:) forControlEvents:(UIControlEventTouchUpInside|UIControlEventTouchUpOutside)];
查看更多
登录 后发表回答