Nsicationicationcenter is specially set for message communication between different classes in the program, which is extremely convenient to use,
Long story short.
Set the notification, that is, where (which class) the notification is to be received, which is generally done during initialization.
[[Nsicationcenter center defacenter center] addObserver: self selector: @ selector (test :) name: @ "test" object: nil];
I will only describe the above parameters:
AddObserver is the observer, that is, where to receive notifications;
Selector: The method called after receiving the notification;
Name: This is the name of the notification and the unique identifier of the notification. The compiler will find the notification through this.
To send a notification, you must call the method at the observer.
[[Nsicationcenter center defacenter center] postNotificationName: @ "test" object: searchFriendArray];
I will only describe the above parameters:
PostNotificationName: the name of the notification, which is the unique identifier of the notification. The compiler will find the notification through this.
Object: transmitted Parameters
The test method is called by default when a notification is sent.
-(Void) test :( NSNotification *) notification
{
SearchFriendArrary = [notification object]; // get the passed object through this
}
========================================================== ========================
Example ::
========================================================== ========================
@ Implementation chuanzhenAppDelegate
-(Void) onSocket :( AsyncSocket *) sock didReadData :( NSData *) data withTag :( long) tag
{
// Send different messages based on the received messages. Send Login here
[[Nsicationcenter center defacenter center] postNotificationName: @ "Login" object: self];
}
Another BeforeRootViewController. m.
-(Void) viewDidLoad {
[[Nsicationcenter center defacenter center] addObserver: self selector: @ selector (DidLogin) name: @ "Login" object: nil];
}
-(IBAction) LoginClick
{
..............
}
From ruanashi