object实现
//在发送通知时设置object参数
[[NSNotificationCenter defaultCenter]
postNotificationName:@"ThisIsANoticafication" object:@{@"parameter1":@"1",@"parameter2":@"2"}];
//这里传入了一个字典,那么如何在接收通知的时候得到这个字典呢
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(getNotificationAction:) name:@"ThisIsANoticafication" object:nil];
//方法
- (void)getNotificationAction:(NSNotification *)notification{
NSDictionary * infoDic = [notification object];
// 这样就得到了我们在发送通知时候传入的字典了
}
userinfo实现
//发通知
NSDictionary *myDictionary = [NSDictionary dictionaryWithObject:@"sendValue" forKey:@"sendKey"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"myNotice" object:nil userInfo:myDictionary];
//接受通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noticeMethod:) name:@"myNotice" object:nil];
//调用方法,接受信息。
- (void)noticeMethod:(NSNotification *)notification
{
NSString *getsendValue = [[notification userInfo] valueForKey:@"sendKey"];
}