Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you make custom events with UIControlEventApplicationReserved?

I have written a subclass of UIControl that tracks a number of gestures that are of interest to me. In the documentation for the UIControlEvents enumeration, it says that there is a range of event numbers called UIControlEventApplicationReserved that is "available for application use." Does this mean that I am free to use this range of numbers for my own custom events?

If so, can someone please tell me how to fire events? The obvious way I can think of to do it is this:

enum {
     ...
     MyCustomEvent = 65,
     ...
};

...

UIEvent* customEvent;

...

for (id target in [self allTargets])
{
     for (NSString* action in [self actionsForTarget:target forControlEvent:MyCustomEvent])
     {
          [self sendAction:NSSelectorFromString(action) to:target forEvent:customEvent];
     }
}

Would that even work?

like image 781
Leo Avatar asked Sep 03 '09 06:09

Leo


People also ask

How do I create a custom event?

A custom event can be created using the CustomEvent constructor: const myEvent = new CustomEvent("myevent", { detail: {}, bubbles: true, cancelable: true, composed: false, }); As shown above, creating a custom event via the CustomEvent constructor is similar to creating one using the Event constructor.

How do you create a custom event on braze?

To create and manage custom events in the dashboard, go to Manage Settings > Custom Events. From this page, you can view, manage, or blocklist existing custom events, or create a new one.

Which method is used to publish your own custom event?

To publish custom events, we will need an instance of ApplicationEventPublisher and then call the method ApplicationEventPublisher#publishEvent(..) . Another way to publish event is to use ApplicationContext#publishEvent(....) .

What are the two types of custom events?

Application Event: Application events follow a traditional publish-subscribe model. An application event is fired from an instance of a component. All components that provide a handler for the event are notified. Component Event: A component event is fired from an instance of a component.


1 Answers

Okay, this is an old subject but I'm going to add my answer to this. I can't really tell for sure whether you can use this mask for your own application even though I suspect it.

But I can tell you for sure how to use it. For starter this value masks the bits at position 24, 25, 26 and 27. You should write an enum of your own that uses this bits only, for example:

enum {
    MyPrimaryActionEvent = 1 << 24,
    MySecondaryActionEvent = 1 << 25,
};

Once that is done you can register for these actions:

[myButton addTarget:self action:@selector(someAction:) forControlEvents: MyPrimaryActionEvent];

Every time the action MyPrimaryActionEvent is triggered, self will receive the message someAction:. Now how to trigger that action is up to the button itself. In your own UIControl subclass you can trigger the change as follow:

[self sendActionsForControlEvents:MyPrimaryActionEvent];

This will send all the actions to all the targets registered for MyPrimaryActionEvent event. And you're done.

like image 107
Psycho Avatar answered Sep 21 '22 15:09

Psycho