iOS NSNotificationCenter 通知传值

2021-09-02  本文已影响0人  安宇辛

一:发送通知

 //需要传的数据 存放在dict中
 NSDictionary *dict = @{@"id":self.kreposted.shortcode};
 //发送通知  openMedia
 [[NSNotificationCenter defaultCenter] postNotificationName:@"openMedia" object:nil userInfo:dict];

二:接受通知

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openMedia:) name:@"openMedia" object:nil];

三:处理通知传值

-(void)openMedia:(NSNotification*)notification{
    //取值
    NSString * shortcode = notification.userInfo[@"id"];
   //处理传过来的数据
    
}
上一篇 下一篇

猜你喜欢

热点阅读