Time for action – adding our own buttons to our dialog
To add custom events for our dialogs, we just need to follow these steps:
Inside the
Dialog.h
file, we need to define the event names before the interface declaration:#define EVENT_TYPE_YES_TRIGGERED @"yesTriggered" #define EVENT_TYPE_NO_TRIGGERED @"noTriggered"
Switch to
Dialog.m
.Register the following listeners to our buttons:
[buttonYes addEventListener:@selector(onButtonYes:) atObject:self forType:SP_EVENT_TYPE_TRIGGERED]; [buttonNo addEventListener:@selector(onButtonNo:) atObject:self forType:SP_EVENT_TYPE_TRIGGERED];
Implement the
onButtonYes
andonButtonNo
methods, as shown in the following code:- (void)onButtonYes:(SPEvent *)event { SPEvent *localEvent = [SPEvent eventWithType:EVENT_TYPE_YES_TRIGGERED]; [self dispatchEvent:localEvent]; } - (void)onButtonNo:(SPEvent *)event { SPEvent *localEvent = [SPEvent eventWithType:EVENT_TYPE_NO_TRIGGERED]; [self dispatchEvent:localEvent]; }
Switch to
Battlefield.m
.The local...