码迷,mamicode.com
首页 > 其他好文 > 详细

postNotificationName 消息传递详解

时间:2015-11-09 18:54:04      阅读:719      评论:0      收藏:0      [点我收藏+]

标签:

 
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 的参数。

 

postNotificationName 消息传递详解

标签:

原文地址:http://www.cnblogs.com/496668219long/p/4950602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!