zoukankan      html  css  js  c++  java
  • [ios]自定义Notifacion

    1.通知者

    想发送通知消失的时候

    NSString * test=@"mytest";

      NSDictionary * notifyObject= [NSDictionary dictionaryWithObjectsAndKeys:test,@"test",nil];

     [[NSNotificationCenter defaultCenter] postNotificationName: @"myNotification" object:mynotifyObject];

    这里notifyObject为参数要字典形式,如果没有参数可写nil

    myNotification 为通知者名称(id) 通过这个区别于其他的通知中心,一般定义为全局的变量。

    2.接收通知者

    先注册一个通知中心(一般写在viewdidload里), 名称和发送的通知中心要保持一致

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

    接收通知后系统会自己调用mynotificationFunc: 方法

    -(void) notificationFunc:(NSNotification *)nt{

    //接收参数

    NSDictionary * dic=(NSDictionary*)[nt object];

    NSString *test=[dic objectForKey:@"test"];

    NSlog(@"%@",test);

    }

    很简单。。。

  • 相关阅读:
    .net 自带的两个内置委托
    Socket
    SQL EXISTS与IN的区别(2)
    一个选择题,写了一个类
    SQL Server- 存储过程(2)
    VS插件-JSEnhancements
    SQL Server- 存储过程(1)
    MVC-工作原理
    C#-属性
    SQL Server 中游标的使用
  • 原文地址:https://www.cnblogs.com/jinjiantong/p/2961100.html
Copyright © 2011-2022 走看看