美文网首页
iOS NSNotificationCenter 通知传值

iOS NSNotificationCenter 通知传值

作者: 安宇辛 | 来源:发表于2021-09-02 09:15 被阅读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"];
   //处理传过来的数据
    
}

相关文章

  • iOS NSNotificationCenter 通知传值

    一:发送通知 二:接受通知 三:处理通知传值

  • 无标题文章

    第一步:注册通知 NSNotificationCenter 在 init或在需要传值的里面注册这个通知, /** ...

  • iOS消息NSNotificationCenter通知传值到不同

    首先,先注册一个消息通知: 然后,另一个界面接收传来的通知: 实现方法: 这样子就可以了

  • 通知

    iOS中通知的使用NSNotificationCenter

  • 无标题文章

    3:通知传值 通知中心 NSNotificationCenter提供了一种更加解耦的方式。最典型的应用就是任何对象...

  • iOS 通知

    iOS 通知传参使用方法 尽量不要在viewWillDisappear:方法中移除通知 iOS通知传值的使用 1、...

  • iOS页面传值

    常用 + 代码 属性传值 方法传值 Block Delegate NSNotificationCenter传参 N...

  • iOS NSNotificationCenter通知中心传值

    主要方法: 使用方法: 1、在需要监听到地方(任何类),添加通知中心观察者,只要有触发,就会回调方法 observ...

  • iOS的五种传值

    前言 iOS常见的五种传值分别为属性传值,通知传值,代理传值,block传值,单例传值 属性传值 用于正向传值,简...

  • NSNotificationCenter的通知名

    NSNotificationCenter的通知名(iOS7.0) 来自Github

网友评论

      本文标题:iOS NSNotificationCenter 通知传值

      本文链接:https://www.haomeiwen.com/subject/qgeqwltx.html