/ Published in: Objective C

Delegate is the object that are listning to Delegatior.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Delegatior.h #import <Foundation/Foundation.h> @protocol SaveActionDelegate; id <SaveActionDelegate> delegate; } @property (nonatomic, assign) id <SaveActionDelegate> delegate; - (IBAction)cancel:(id)sender; - (IBAction)save:(id)sender; @end @protocol SaveActionDelegate - (void)delegationObject:(Delegatior *)obj didSave:(BOOL)save; @end // Delegatior.m #import "Delegatior.h" @implementation Delegatior @synthesize delegate; - (IBAction)cancel:(id)sender { [delegate delegationObject:self didFinishWithSave:NO]; } - (IBAction)save:(id)sender { [delegate delegationObject:self didFinishWithSave:YES]; } - (void)dealloc { [delegate release]; [super dealloc]; } @end // Delegate.h #import <Foundation/Foundation.h> #import "Delegatior.h" } - (void)delegationObject:(Delegatior *)obj didSave:(BOOL)save; @end // Delegate.m #import "Delegate.h" @implementation Delegate - (void)viewDidLoad { [super viewDidLoad]; Delegatior *delegatior = [[Delegatior alloc] init]; delegatior.delegate = self; } - (void)delegationObject:(Delegatior *)obj didSave:(BOOL)save { [self doStuff]; } @end
Comments
