如何确定哪个UIControlEvent类型导致UIEvent? [英] How can I determine which UIControlEvents type caused a UIEvent?

查看:100
本文介绍了如何确定哪个UIControlEvent类型导致UIEvent?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是设置一堆 UIControl 对象,通过同一个处理程序发送所有事件。该处理程序需要根据触发的 UIControlEvents 类型来确定适当的操作。

What I want to do is set up a bunch of UIControl objects to send all events through the same handler. That handler than needs to determine what the appropriate action is based on the UIControlEvents type that triggered.

- (void)handleEventFromControl:(id)sender withEvent:(UIEvent *)event {
    UIControl *control = sender;
    NSIndexPath *indexPath = [controlIndexPaths objectForKey:control];
    UIControlEvents controlEventType = event.type; //PROBLEM HERE

    BOOL fire = NO;
    NSNumber *eventCheck = [registeredEventsByToolkitIndex objectAtIndex:indexPath.toolkit];
    fire = ([eventCheck integerValue] & controlEventType);

    if(!fire) {
        eventCheck = [registeredEventsByControlIndex objectAtIndex:indexPath.control];
        fire = ([eventCheck integerValue] & controlEventType);
    }

    if(!fire) {
        eventCheck = [registeredEventsByIndexPath objectForKey:indexPath];
        fire = ([eventCheck integerValue] & controlEventType);
    }

    if(fire) {
        [self.delegate toolkit:self indexPath:indexPath firedEvent:event];
    }
}

尽可能的告诉我, event.type 不能这样工作。我想避免拥有 UIControl 的子类,因为我想要做的是严重的过度杀伤力。这里的其余部分不是那么重要,我想要的是在目标之后检查 UIControlEvents 的方法:action: pair用于以下设置:

As best as I can tell, event.type doesn't work this way. I want to avoid having a subclass of UIControl because that is severe overkill for what I want to do. The rest of the moving parts here aren't really that important; what I want is a way to check against UIControlEvents after the target:action: pair is used in the following setup:

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

如果有一种不同的方式设置目标:action:发回 UIControlEvents ,我会采取。但是我没有在文档中看到它。或者,至少要访问 UIControl 对象的 ,以便我可以获得我想要的类型。

If there is a different way to setup of a target:action: that sends back the UIControlEvents, I'd take that. But I am not seeing it in the documentation. Or, at the very least, get access outside of the UIControl object such that I can get the type I want.

推荐答案

你是对的; UIEvent.type 不会这样工作。在内部, UIControl 子类基本上使用 sendActionsForControlEvents: 方法,这意味着他们可以选择把任何他们想要的东西作为参数。

You're correct; UIEvent.type does not work that way. Internally, UIControl subclasses are basically using the sendActionsForControlEvents: method, which means they can choose to put anything they want as the parameter.

至于如何知道,简单的答案是每个控件事件都有一个单独的方法。

As for how to know, the simple answer is to have a separate method for each control event.

这篇关于如何确定哪个UIControlEvent类型导致UIEvent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆