Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. - (void)mouseDown:(NSEvent *)theEvent {
  2. NSLog(@"mouse down");
  3. }
  4.  
  5. - (IBAction)doStuff:(id)sender {
  6. // do stuff here
  7. }
  8.  
  9. @interface ClickerView : NSControl {
  10. IBOutlet BoothController *controller;
  11. }
  12. @end
  13.  
  14. - (void)mouseDown:(NSEvent *)theEvent {
  15. NSLog(@"mouse down");
  16. [controller start:self];
  17. }
  18.  
  19. @protocol MyViewDelegate
  20. - (void)doStuff:(NSEvent *)event;
  21. @end
  22.  
  23. @interface MyViewController: NSViewController <MyViewDelegate> {
  24. // your other ivars etc would go here
  25. }
  26. @end
  27.  
  28. - (void)doStuff:(NSEvent *)event
  29. {
  30. NSLog(@"Do stuff delegate was called");
  31. }
  32.  
  33. @interface MyView: NSView
  34.  
  35. @property (readwrite, weak) id<MyViewDelegate> delegate;
  36.  
  37. @end
  38.  
  39. - (void)mouseDown:(NSEvent *)event
  40. {
  41. // Do whatever you need to do
  42.  
  43. // Check that the delegate has been set, and this it implements the doStuff: message
  44. if (delegate && [delegate respondsToSelector:@selector(doStuff:)]) {
  45. [delegate doStuff:event];
  46. }
  47. }
  48.  
  49. ...
  50. MyView *view = [viewController view];
  51. [view setDelegate:viewController];
  52. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement