iphone 消息处理事件 postNotificationName和addObserver的调用

来源:互联网 发布:淘宝 127.0.0.1 编辑:程序博客网 时间:2024/05/16 19:19
转自:http://blog.sina.com.cn/s/blog_6853c0db0100n2t1.html
1.定义消息创建的关联值 也就是找到方法的标志

NSString *const GameToIPhoneNotification = @"GameToIPhoneNotification"GameToIPhoneNotification变量,@"GameToIPhoneNotification"这个值存于通知中心中,信息中心通过这个值来识别变量

1.注册一个消息中心

NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

[center addObserver:self selector:@selector(onToIphone:) name:GameToIPhoneNotification object:nil];

-(void)onToIphone:(NSNotification*)notify :这个方法是接受到GameToIPhoneNotification这个通知所调用的方法

2.调用信息

NSNotificationCenter * center = [NSNotificationCenter defaultCenter];

[center postNotificationName:GameToIPhoneNotification object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:SMSRecommendNotification] , @"actcode",nil]];

[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:SMSRecommendNotification] 这个是传递给-(void)onToIphone:(NSNotification*)notify 的参数。


原创粉丝点击