NSNotificationCenter的工作机制

来源:互联网 发布:ai编程算法基础 编辑:程序博客网 时间:2024/05/22 06:56

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"]


原创粉丝点击