Tuesday, 24 November 2015

Work With NSNotification Center Ios/Iphone

=> Here User Dealloct Whiitch Used Notification:
- (void) dealloc
{
   
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}

- (id) init
{
    self = [super init];
    if (!self) return nil;

==> add observe Notification default center:-   

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

    return self;
}

=> have Received Notification:-



 - (void) receiveTestNotification:(NSNotification *) notification
{
    // [notification name] should always be @"TestNotification"
    // unless you use this method for observation of other notifications
    // as well.

    if ([[notification name] isEqualToString:@"TestNotification"])
        NSLog (@"Successfully received the test notification!");
}

@end



- (void) someMethod
{

    // All instances of TestClass will be notified
    [[NSNotificationCenter defaultCenter]
        postNotificationName:@"TestNotification"
        object:self];

}
=================================================================

NSDictionary *userInfo = [NSDictionary dictionaryWithObject:myObject

forKey:@"someKey"];
    [[NSNotificationCenter defaultCenter] postNotificationName:

 @"TestNotification" object:nil userInfo:userInfo]; 



- (void) receiveTestNotification:(NSNotification *) notification

    NSDictionary *userInfo = notification.userInfo;
    MyObject *myObject = [userInfo objectForKey:@"someKey"];
}