3

有没有办法为多个 UIControlEvents 调用选择器?

这不起作用,但它会让你知道我正在尝试做什么。

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

谢谢!!

4

3 回答 3

16

只有OR他们:

[self.button addTarget:self action:@selector(selector0:) forControlEvents:(UIControlEventTouchUpInside|UIControlEventTouchUpOutside)];
于 2013-04-13T14:24:09.407 回答
2

它们现在是一个选项集,因此您可以用于: [.touchUpInside, .touchUpOutide]

于 2020-03-02T11:28:02.260 回答
1

试试这种方式:

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

或者你可以使用这个:

// different selectors for same event
[self.button addTarget:self action:@selector(selector1:) forControlEvents:UIControlEventTouchUpInside];
[self.button addTarget:self action:@selector(selector2:) forControlEvents:UIControlEventTouchUpInside];
// etc...
于 2012-08-23T23:20:53.990 回答