PXEventDispatcher Protocol Reference
| Conforms to | NSObject |
| Declared in | PXEventDispatcher.h |
Overview
The protocol from which the PXEventDispatcher is derived. You should implement this protocol when your class requires event dispatching functionallity but cannot extend the PXEventDispatcher class.
The implementing class should simply create a private PXEventDispatcher object and pass along all method invocations to it.
Example:
We want to create a subclass of SomeOtherClass and we want it
to have event dispatching capabilities. The easy thing to do would be to
have our class extend PXEventDispatcher. But since it already extends from
SomeOtherClass we need a different solution. The solution is
to implement the PXEventDispatcher protocol, since one class can implement
any number of protocols but only inherit from a single class. Here’s what
our class would need to do to support the PXEventDispatcher protocol:
Header:
#import "SomeOtherClass.h"
#import "PXEventDispatcher.h"
@interface MyEventDispatchingClass : SomeOtherClass <PXEventDispatcher>
{
@private
PXEventDispatcher *eventDispatcher;
}
@end
Implementation:
#import "MyEventDispatchingClass.h"
@implementation MyEventDispatchingClass
- (id) init
{
self = [super init];
if (self)
{
eventDispatcher = [[PXEventDispatcher alloc] initWithTarget:self];
}
return self;
}
- (void) dealloc
{
[eventDispatcher release];
eventDispatcher = nil;
[super dealloc];
}
// Implementation of protocol methods. They just pass the parameters to the
// internal PXEventDispatcher object.
- (BOOL) addEventListenerOfType:(NSString *)type
listener:(PXEventListener *)listener
useCapture:(BOOL)useCapture
priority:(int)priority
{
return [eventDispatcher addEventListenerOfType:type listener:listener useCapture:useCapture priority:priority];
}
- (BOOL) removeEventListenerOfType:(NSString *)type
listener:(PXEventListener *)listener
useCapture:(BOOL)useCapture
{
return [eventDispatcher removeEventListenerOfType:type listener:listener useCapture:useCapture];
}
- (BOOL) dispatchEvent:(PXEvent *)event
{
return [eventDispatcher dispatchEvent:event];
}
- (BOOL) hasEventListenerOfType:(NSString *)type
{
return [eventDispatcher hasEventListenerOfType:type];
}
- (BOOL) willTriggerEventOfType:(NSString *)type
{
return [eventDispatcher willTriggerEventOfType:type];
}
@end
Tasks
-
– addEventListenerOfType:listener:useCapture:priority:Adding an event listener.
required method -
– removeEventListenerOfType:listener:useCapture:Removing an event listener.
required method -
– dispatchEvent:Dispatching an event.
required method -
– hasEventListenerOfType:Querying registered events.
required method -
– willTriggerEventOfType:Querying registered events.
required method
Instance Methods
addEventListenerOfType:listener:useCapture:priority:
Adding an event listener.
- (BOOL)addEventListenerOfType:(NSString *)type listener:(PXEventListener *)listener useCapture:(BOOL)useCapture priority:(int)priorityDeclared In
PXEventDispatcher.hdispatchEvent:
Dispatching an event.
- (BOOL)dispatchEvent:(PXEvent *)eventDeclared In
PXEventDispatcher.hhasEventListenerOfType:
Querying registered events.
- (BOOL)hasEventListenerOfType:(NSString *)typeDeclared In
PXEventDispatcher.h