objective 消息中心的处理
来源:互联网 发布:433m模块stc单片机解码 编辑:程序博客网 时间:2024/05/16 11:14
先注册消息
//接收消息(被攻击)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(IS_attacked:)
name:@"bird_attack_pig"
object:nil];
//接收消息(攻击)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(IS_attack:)
name:@"pig_attack_bird"
object:nil];
//接收消息(武器升级)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(WEAPON_up:)
name:@"weapon_up"
object:nil];
//linbo code
//pig_bossdart 发出武器
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(pig_bossdart:)
name:@"pig_bossdart"
object:nil];
注册后当有消息发过来,自动会调用selector 里的方法,name 为对应的消息名
下面是一个上面用的事调用方法
-(void)pig_bossdart:(NSNotification *)sender
{
NSDictionary *ns=[sender object];
NSNumber *level= [ns objectForKey:@"level"];
int a = [level intValue];
NSNumber *direction= [ns objectForKey:@"direction"];
int b=[direction intValue];
[pig bossdart_attack:a direction:b];
[pig setDelegate:self];
}
这里的sender 其实就是在其它地方发送消息传过来的参数,
发送消息
//调用pig的动做
NSNumber *temp_level;
NSNumber *temp_direction;
temp_level =[NSNumber numberWithInt:level1];
temp_direction=[NSNumber numberWithInt:direction1];
//
NSMutableDictionary *dict=[NSMutableDictionary dictionary];
[dict setObject:sender forKey:@"bossdart"];
[dict setObject:temp_level forKey:@"level"];
[dict setObject:temp_direction forKey:@"direction"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"pig_bossdart" object:dict];
pig_bossdart 为消息名,,,dict 为参数
- objective 消息中心的处理
- 消息中心的使用
- Objective-C performSelector: withObject: 消息处理方法
- Objective-C的消息机制
- ios-消息中心 NSNotificationCenter 的介绍
- 对消息中心CCNotificationCenter的封装
- 消息调度中心的学习资料汇总
- 基于Redis的消息中心缓存搭建
- Rabbitmq消息中心_消息中心总体方案
- RabbitMqx消息中心_消息中心一致性
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector: withObject:
- Objective-C中一种消息处理方法performSelector withObject
- Objective-C中一种消息处理方法performSelector: withObject:
- win7 32 安装oracle server 10.2.0.1.0
- s3c2440定时器简介
- 使用jQuery实现鼠标悬浮图片轮换效果
- hibernate 多对一映射 many-to-one
- nginx location的管理以及查找
- objective 消息中心的处理
- python时间函数
- 移动视频分享应用Klip获Benchmark领投800万B轮融资
- vim自动补全功能
- 找出两个已经排好序的数组的中位数
- hibernate criteria查询
- C#Socket 通信
- 【产品经理】谁是产品经理,产品经理到底要做什么?
- 如何两个栈实现队列?两个队列实现栈?