Follow by Email

Search This Blog

Friday, 20 December 2013

iOS NSNotification

NSNotification is a great and simple way to inform other 
methods to trigger in different classes
eg : we have two classes : class A and class B , in class B 
we perform some tasks and we have to inform class A that 
class B has finished it's task so, we can handle this by
simple implementation of two piece of code : one is post 
notification which has to implement in class B and other one
will be implemented in class A which will receive notification from class 

Class B:
Below method you can implement after completing any task with any
 key liek ("Task_done")

    [[NSNotificationCenter defaultCenter]
     postNotificationName:@"Task_done"

     object:self];

Class A:
This class will receive notification with the same key , and it
 will automatically call the method (AfterTaskDone:)

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(AfterTaskDone:)

                                                 name:@"Task_done"        object:nil];

-(void)AfterTaskDone{
    

}

No comments:

Post a Comment