-3

I wants to know about NSNotification in Objective C ,can any one tell me about right Source

GauravBoss
  • 140
  • 2
  • 4
  • 13
  • [From here you can start, Seriously!!](http://www.google.com/search?q=NSNotification) and specially [this one](http://stackoverflow.com/q/1900352/593709) – Adil Soomro Feb 06 '12 at 10:21
  • 1
    the [doc](https://developer.apple.com/library/IOs/#documentation/Cocoa/Reference/Foundation/Classes/NSNotification_Class/Reference/Reference.html) ? –  Feb 06 '12 at 10:21

2 Answers2

1

To send a notification:

[[NSNotificationCenter defaultCenter] postNotificationName:@"MyNotification" object:nil];

To register a class to receive the notification (normally in the init method):

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myCallback:) name:@"MyNotification" object:nil];

- (void)myCallback:(NSNotification *)notification
{
    ... do something
}

Then to remove the observer in your dealloc

[[NSNotificationCenter defaultCenter] removeObserver:self];
Nick Lockwood
  • 40,865
  • 11
  • 112
  • 103
0

This is a very diffuse question.

If you want to read about NSNotifications, head over to the NSNotification Class Reference on developer.apple.com

hellozimi
  • 1,858
  • 19
  • 21