UIControl: sendActionsForControlEvents omits UIEvent

后端 未结 2 2003
有刺的猬
有刺的猬 2020-12-18 07:28

I want to implement a custom subclass of UIControl. It works beautifully except for one fatal problem that is making me spit teeth. Whenever I use sendActionsForControlEvent

2条回答
  •  醉话见心
    2020-12-18 08:27

    I would assume that this is because the sendActionsForControlEvents: method can't know which UIEvent (if any) your control event should be associated with.

    You could try to send all the actions separately (replicating what the sendActionsForControlEvents: method does, according to the documentation), so you can specifically associate them with a UIEvent:

    UIEvent *event = ...;
    UIControlEvents controlEvent = ...;
    
    for (id target in [self allTargets]) {
        NSArray *actions = [self actionsForTarget:target forControlEvent:controlEvent];
        for (NSString *action in actions) {
            [self sendAction:NSSelectorFromString(action) to:target forEvent:event];
        }
    }
    

提交回复
热议问题