#warning通知第一步,注册通知
// NSNotification消息通知类,是抽象类,使用他的子类,消息中心单例 [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(changeColor:)name:@”changeColor”object:nil]; #warning通知第二步,实现通知触发的方法
//当收到通知后,该方法会被执行
-(void)changeColor:(NSNotification*)notification
{
#warning通知第四步,接收消息
UIColorcolor = (UIColor)[notificationobject];
self.view.backgroundColor= color;}
#warning通知第三步,发送通知
[[NSNotificationCenterdefaultCenter]postNotificationName:@”changeColor”object:[UIColorredColor]]; [[NSNotificationCenterdefaultCenter]postNotificationName:@”changeColor2”object:[UIColorredColor]];
- (void)dealloc
{
[[NSNotificationCenterdefaultCenter]removeObserver:selfname:@”changeColor”object:nil];
[superdealloc];}