Posted By

vaishnavi on 04/12/11


Tagged

Delegate


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

vaishnavi
Tintenklecks
cnathan


writing a custom delegate


 / Published in: Objective C
 

  1. //interface file is SampleController.h
  2.  
  3. //in SampleController.h
  4.  
  5.  
  6. @protocol SampleControllerDelegate;
  7.  
  8.  
  9. @interface SampleController : UIViewController <> {
  10. id<SampleControllerDelegate> delegate;
  11. }
  12.  
  13. @property(nonatomic,assign) id<SampleControllerDelegate> delegate;
  14.  
  15. @end
  16.  
  17. @protocol SampleControllerDelegate <NSObject>
  18.  
  19. - (void)testFunction:(SampleController*)controller;
  20.  
  21. @end
  22.  
  23.  
  24. //in SampleController.m file
  25.  
  26. @synthesize delegate
  27.  
  28.  
  29.  
  30. // implement SampleControllerDelegate like this
  31.  
  32. - (void)yourCustomFunction:(id)sender {
  33. [delegate testFunction:self];
  34. }

Report this snippet  

You need to login to post a comment.