NSNotificationCenter的工作机制
1.消息的代理方法
-(void) playNotification:(NSNotification*) value
{
NSString *currentValue = (NSString*)[value object];
NSDate *currentDate = [NSDate date];
NSLog(@"当前时间%@发布消息的参数%@",currentDate,currentValue);
}
2.向消息中心参加消息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playNotification:) name:@“slyNotification" object:nil];
3.发布消息
[[NSNotificationCenter defaultCenter] postNotificationName:@“slyNotification" object:@"sly"]