objective-ciosxcodensstringuicontrolevents

UIControlEvents variable from a string


Is it possible to create a UIControlEvents variable from a NSString or similar? So for example, I might have a NSString that is called UIControlEventTouchUpInside which is the same as one of the typedefs for the UIControlEvents variable.

Thanks for all help!


Solution

  • If I understand how this works correctly, UIControlEvents are enumerated as follows:

    enum {
       UIControlEventTouchDown           = 1 <<  0,
       UIControlEventTouchDownRepeat     = 1 <<  1,
       UIControlEventTouchDragInside     = 1 <<  2,
       UIControlEventTouchDragOutside    = 1 <<  3,
       UIControlEventTouchDragEnter      = 1 <<  4,
       UIControlEventTouchDragExit       = 1 <<  5,
       UIControlEventTouchUpInside       = 1 <<  6,
       UIControlEventTouchUpOutside      = 1 <<  7,
       UIControlEventTouchCancel         = 1 <<  8,
    
       UIControlEventValueChanged        = 1 << 12,
    
       UIControlEventEditingDidBegin     = 1 << 16,
       UIControlEventEditingChanged      = 1 << 17,
       UIControlEventEditingDidEnd       = 1 << 18,
       UIControlEventEditingDidEndOnExit = 1 << 19,
    
       UIControlEventAllTouchEvents      = 0x00000FFF,
       UIControlEventAllEditingEvents    = 0x000F0000,
       UIControlEventApplicationReserved = 0x0F000000,
       UIControlEventSystemReserved      = 0xF0000000,
       UIControlEventAllEvents           = 0xFFFFFFFF
    };
    

    So once again, this is if I'm understanding this correctly so correct me if I'm wrong, but you should be able to make a variable integer and pass it to the control event like so:

        int myVariable = 64;
        [myButton addTarget:self action:@selector(mySelector) forControlEvents:myVariable];
    

    See this link for explanation of Bitwise Shift Left