zoukankan      html  css  js  c++  java
  • NSNotificationCenter通知中心

    概述

    NSNotificationCenter通知中心,通常用于一对一或者一对多的消息传递,即当一个地方改变时,要求改变其他的一些地方,例如当网络请求回来了新的数据,需要刷新本地信息和本地内存里面的界面时,当这些页面不只一个时就可以考虑使用通知中心


    注册一个通知

    代码实现

    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

    [notificationCenter addObserver:self selector:@selector( ) name: object:nil];

    发布通知中心事件

    代码实现

    NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:...];

    [[NSNotificationCenter defaultCenter] postNotificationName: object:nil userInfo:dic];

    注:dic为传给selector的参数

    通知的响应事件

    -(void)action:(NSNotification *)sender{

    NSDictionary *dic = [sender userInfo];

    }

    从通知中心移除通知

    [[NSNotificationCenter defaultCenter] removeObserver:self name: object:nil];

  • 相关阅读:
    iOS 面试题汇总
    iOS管理文件和目录
    文件管理
    Cocoapods依赖管理
    IOS开发几何类方法 CGGeometry.h文件
    CGContext
    respondsToSelector的相关使用
    Java数组5作业(2015-8-27)
    Java错误1(2015-8-27)
    Java数组4(2015-8-27)
  • 原文地址:https://www.cnblogs.com/IOS-Developer/p/4117232.html
Copyright © 2011-2022 走看看