zoukankan      html  css  js  c++  java
  • OC通知实例

    #import "NotificationClass.h"

    #import "AnotherNotificationClass.h"

    @implementation NotificationClass

    //注册通知

    -(void)addNotification

    {

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

    }

    -(void)changeFun:(NSNotification *)sender

    {

        NSDictionary *getDic=[sender userInfo];

        NSLog(@"NotificationClass 接收到通知事件,传递的值:%@",getDic);

    }

    //发送通知

    -(void)postNotification

    {

        NSDictionary *dictionary=[NSDictionary dictionaryWithObject:@"newValue" forKey:@"obj"];

        [[NSNotificationCenter defaultCenter] postNotificationName:@"change" object:self userInfo:dictionary];//发送给自己

        

        if (!another) {

            another=[[AnotherNotificationClass alloc]init];

        }

        [[NSNotificationCenter defaultCenter] postNotificationName:@"change" object:another userInfo:dictionary];//发送给another

        

    }

    //移除通知

    -(void)removeNotification

    {

        [[NSNotificationCenter defaultCenter]removeObserver:self];

    }

    @end

  • 相关阅读:
    进度条与拖动条的使用学习
    双指针,BFS和图论(三)
    dubbo文档笔记
    ByteBuf
    Netty源码解析—客户端启动
    Netty源码解析---服务端启动
    java并发程序和共享对象实用策略
    docker命令
    elasticSearch基本使用
    Filebeat6.3文档—Log input配置
  • 原文地址:https://www.cnblogs.com/shuxiachahu123/p/4951851.html
Copyright © 2011-2022 走看看