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"];
本文介绍如何在Objective-C中使用NSNotification进行消息传递。主要内容包括定义代理方法处理通知、注册观察者监听特定消息以及发布自定义通知。
763

被折叠的 条评论
为什么被折叠?



