首页 > 其他 > 详细

OC通知实例

时间:2015-11-10 09:20:54      阅读:183      评论:0      收藏:0      [点我收藏+]

#import "NotificationClass.h"

#import "AnotherNotificationClass.h"

 

@implementation NotificationClass

 

//注册通知

-(void)addNotification

{

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeFun:) name:@"change" object:nil];

}

 

-(void)changeFun:(NSNotification *)sender

{

    NSDictionary *getDic=[sender userInfo];

    NSLog(@"NotificationClass 接收到通知事件,传递的值:%@",getDic);

}

//发送通知

-(void)postNotification

{

    NSDictionary *dictionary=[NSDictionary dictionaryWithObject:@"newValue" forKey:@"obj"];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"change" object:self userInfo:dictionary];//发送给自己

    

    if (!another) {

        another=[[AnotherNotificationClass alloc]init];

    }

    [[NSNotificationCenter defaultCenter] postNotificationName:@"change" object:another userInfo:dictionary];//发送给another

 

    

}

 

//移除通知

-(void)removeNotification

{

    [[NSNotificationCenter defaultCenter]removeObserver:self];

}

 

 

@end

 

OC通知实例

原文:http://www.cnblogs.com/shuxiachahu123/p/4951851.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!