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”];
}
本文介绍了如何使用NSNotification进行消息传递。首先展示了如何发送NSNotification,并通过NSDictionary携带数据。接着讲解了如何接收NSNotification并从中获取发送的数据。
842

被折叠的 条评论
为什么被折叠?



