Это именно то, что уведомляет центр: это, по сути, доска объявлений, на которой классы могут размещать материалы, которые могут интересовать другие классы, не зная их (или заботясь, если кто-то действительно заинтересован).
Так это класс, который имеет что-то интересное, чтобы сказать (класс А из вашего вопроса) просто отправляет уведомление на центральную Доску:
//Construct the Notification
NSNotification *myNotification = [NSNotification notificationWithName:@"SomethingInterestingDidHappenNotification"
object:self //object is usually the object posting the notification
userInfo:nil]; //userInfo is an optional dictionary
//Post it to the default notification center
[[NSNotificationCenter defaultCenter] postNotification:myNotification];
В каждом классе, уже заинтересованные в получении уведомлено (классы В и С в вашем вопросе), вы просто добавить себя в качестве наблюдателя в центр уведомлений по умолчанию:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@SEL(methodYouWantToInvoke:) //note the ":" - should take an NSNotification as parameter
name:@"SomethingInterestingDidHappenNotification"
object:objectOfNotification]; //if you specify nil for object, you get all the notifications with the matching name, regardless of who sent them
вы также реализовать метод, указанный в части @SEL()
выше в классах B и C. простой пример будет выглядеть следующим образом :
//The method that gets called when a SomethingInterestingDidHappenNotification has been posted by an object you observe for
- (void)methodYouWantToInvoke:(NSNotification *)notification
{
NSLog(@"Reacting to notification %@ from object %@ with userInfo %@", notification, notification.object, notification.userInfo);
//Implement your own logic here
}
Apple может объяснить это очень хорошо: http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Notifications/ –