writing a custom delegate


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.