Skip to content

iPhone Event Dispatching

by Colin on August 5th, 2010

Here are the basics of Event Handling for Objective C.

  1.  
  2. // To listen for an event.
  3. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eventHandler:) name:@"eventName" object:nil];
  4.  
  5. // The event handler
  6. -(void)eventHandler:(NSNotification *)notification
  7. {
  8. NSLog(@"Event triggered!");
  9. }
  10.  
  11. // Dispatching the event
  12. [[NSNotificationCenter defaultCenter] postNotificationName:@"eventName" object:nil];
  13.  

From → iPhone, Xcode

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS