您的位置:首页 > 其它

NSNotificationCenter通知,用userInfo实现

2016-01-12 17:07 330 查看
1、发通知

NSDictionary *myDictionary = [NSDictionary dictionaryWithObject:@”sendValue” forKey:@”sendKey”];

//这里是一个dic格式数据,可以放入各种数据

[[NSNotificationCenter defaultCenter] postNotificationName:@"myNotice" object:nil userInfo:myDictionary];


2、接受通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noticeMethod:) name:@”myNotice” object:nil];

3、调用方法,接受信息。

- (void)noticeMethod:(NSNotification *)notification

{

//在这里可以得到想要的数据

NSString *getsendValue = [[notification userInfo] valueForKey:@”sendKey”];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: