TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Sep 2015 |
Maintained by KptainO.
EventListener is an Obsever design pattern implementation with an API very similar to those from Javascript/ActionScript DOM including:
More information on DOM events here
Like EventListener, NSNotification implement the Obsever design pattern: you subscribe to events/notifications. And it is very good at doing one job: getting global (or from specific set of objects) notifications. But it lacks some crucial functionalities when working with UI:
EventListener tries to overtake those limitations and even more by bringing the well-known Javascript DOM API to iOS
NOTE: You should still continue to use NSNotification when you want to send global notifications
API behaves a lot like the one from DOM events. All you need to do is:
extern NSString *MyCustomEventClicked;
extern NSString *MyCustomEventDoubleClicked;
@interface MyCustomEvent : EVEEvent
// Add all your custom event properties
@end
@implementation aViewController
- (void)aMethod {
[self addEventListener:MyCustomEventCliked listener:@selector(onClicked:) useCapture:YES];
}
- (void)onClicked:(MyCustomEvent *)event {
// Do whatever you want
}
@end
/// somewhere in your code
MyCustomEvent *event = [MyCustomEvent event:MyCustomEventClicked];
// configure it
[self dispatchEvent:event];
NOTE: UIViewController and UIView are event listeners ready. So you can trigger and listen to events inside those classes right away!
EventListener is dispatching the event along the iOS responder chain. That's how both UIViewConttoller and UIView are able to trigger and/or listen to events