object c NSNotificationCenter 通知中心
来源:互联网 发布:java实现相似图片搜索 编辑:程序博客网 时间:2024/05/10 12:54
Object C的NSNotificationCenter类似android的广播
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@implementation Boss
-(void)sendNotification
{
//发送通知
NSDictionary *message = @{@"notification" : @"contacts every one!"};
//创建通知对象(老板登陆boss账号)
NSNotification * notification = [NSNotification notificationWithName:@"fky" object:self userInfo:message];
//向通知中心发送消息(发布消息)
[[NSNotificationCenter defaultCenter] postNotification:notification];
}
@end
注意:notificationWithName 需要和addObserver 的name 一样
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
@implementationHumanResources
-(instancetype)init
{
self=[superinit];
if (self){
//注册监听
[[NSNotificationCenterdefaultCenter] addObserver:self selector:@selector(doSomething:) name:@"fky" object:nil];
}
return self;
}
-(void)doSomething:(NSNotification*)notification
{
//处理的方法
NSDictionary*rec=[notificationuserInfo];
//输出收到的信息
NSLog(@"收到广播:%@",rec[@"notification"]);
}
@end
0 0
- object c NSNotificationCenter 通知中心
- 通知中心NSNotificationCenter
- 通知中心 NSNotificationCenter
- IOS NSNotificationCenter 通知中心
- 通知中心(NSNotificationCenter)
- NSNotificationCenter 通知中心
- 通知中心NSNotificationCenter
- NSNotificationCenter通知中心
- IOS NSNotificationCenter 通知中心
- NSNotificationCenter通知中心
- iOS通知中心(NSNotificationCenter)
- NSNotificationCenter(通知中心)
- 通知中心NSnotificationCenter
- iOS通知中心NSNotificationCenter
- 通知中心(NSNotificationCenter)
- 通知中心(NSNotificationCenter)
- NSNotificationCenter通知中心
- NSNotificationCenter通知中心
- 项目中遇到的bug及相关经验
- Android开发本地及网络Mp3音乐播放器(五)实现专辑封面图片
- Reduction to two dimensions and Phase plane analysis
- Objective-C 单例模式
- LeetCode 230. Kth Smallest Element in a BST
- object c NSNotificationCenter 通知中心
- 207. Course Schedule
- 2016年湖南中医药大学考博英语考.试答.案《466068743+考過付》
- 1-JavaScript简介
- 2-JavaScript基础
- 3-BOM和DOM
- LeetCode 205. Isomorphic Strings
- 4-DOM简介-核心DOM
- 5-HTML DOM简介和新特性