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"];
}

相关文章:

  • 2022-01-05
  • 2022-12-23
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-27
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2020-05-08
  • 2021-11-08
相关资源
相似解决方案