简体   繁体   English

在UIButton上使用两个不同的控件事件

[英]use two different control-event on UIButton

I have created one dynamic button in my application and I call the following method: 我在应用程序中创建了一个动态按钮,并调用以下方法:

[btnactions addTarget:self 
               action:@selector(deleteview:)
     forControlEvents:UIControlEventTouchDown];</b>

This deleteview method is used for delete the specific application view whenever I click the button. 每当单击按钮时,此deleteview方法用于删除特定的应用程序视图。

Now, I want another method to call dynamically on button event 现在,我希望另一个方法可以在按钮事件上动态调用

UIControlEventTouchDownRepeat

So how can I call two different events using different control events? 那么,如何使用不同的控制事件来调用两个不同的事件呢?

You can call addTarget again with UIControlEventTouchDownRepeat 您可以使用UIControlEventTouchDownRepeat再次调用addTarget

From the docs (UIButton inherits from UIControl ): 从文档(UIButton继承自UIControl ):

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents

You may call this method multiple times, and you may specify multiple target-action pairs for a particular event. 您可以多次调用此方法,并且可以为特定事件指定多个目标操作对。 The action message may optionally include the sender and the event as parameters, in that order. 动作消息可以有选择地按该顺序包括发送方和事件作为参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM