有没有办法为多个 UIControlEvents 调用选择器?
这不起作用,但它会让你知道我正在尝试做什么。
[self.slider addTarget:self action:@selector(sliderDidStopDragging:) forControlEvents:UIControlEventTouchUpInside, UIControlEventTouchUpOutside];
谢谢!!
有没有办法为多个 UIControlEvents 调用选择器?
这不起作用,但它会让你知道我正在尝试做什么。
[self.slider addTarget:self action:@selector(sliderDidStopDragging:) forControlEvents:UIControlEventTouchUpInside, UIControlEventTouchUpOutside];
谢谢!!
只有OR
他们:
[self.button addTarget:self action:@selector(selector0:) forControlEvents:(UIControlEventTouchUpInside|UIControlEventTouchUpOutside)];
它们现在是一个选项集,因此您可以用于: [.touchUpInside, .touchUpOutide]
试试这种方式:
// 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...