UIResponder and multiple UIControlEvents

北战南征 提交于 2019-12-24 00:25:45

问题


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


回答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...



回答2:


Just OR them:

[self.button addTarget:self action:@selector(selector0:) forControlEvents:(UIControlEventTouchUpInside|UIControlEventTouchUpOutside)];


来源:https://stackoverflow.com/questions/12101108/uiresponder-and-multiple-uicontrolevents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!