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

  • 相关阅读:
    学长帮帮忙—Beta冲刺(4/7)
    学长帮帮忙—Beta冲刺(3/7)
    【二食堂】二食堂很难排队 博客目录
    【二食堂】Beta
    【二食堂】Beta
    【二食堂】Beta
    【二食堂】Beta
    【二食堂】Beta
    【二食堂】Beta
    【二食堂】Beta
  • 原文地址:https://www.cnblogs.com/shuxiachahu123/p/4951851.html
Copyright © 2011-2022 走看看