NSNotificationCenter主要用于广播消息到多个监听着,其传统用法

 - (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someMethod:) name:kMyNotificationIdentifier object:nil];
} - (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
} - (void)someMethod:(NSNotification *)note
{
// Message received
}

利用Blocks操作

@implementation MyViewController
{
id _notificationObserver;
} // ... - (void)viewDidLoad
{
[super viewDidLoad];
_notificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMyNotificationIdentifier object:nil queue:nil usingBlock:^(NSNotification *note) {
// message received
}];
} // dealloc, or potentially a method popping this view from the stack
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:_notificationObserver];
}

关于NSNotificationCenter消息通信用法的更多相关文章

  1. NSNotificationCenter消息通信机制

    作用:NSNotificationCenter是专门供程序中不同类间的消息通信而设置的. 注册通知:即要在什么地方接受消息 [[NSNotificationCenter defaultCenter] ...

  2. NSNotificationCenter消息通信(KVO)

    NSNotificationCenter是程序不同类间的消息通信. 注册消息通知: [[NSNotificationCenter defaultCenter]addObserver:self sele ...

  3. 消息通信机制NSNotificationCenter -备

    消息通信机制NSNotificationCenter的学习.最近写程序需要用到这类,研究了下,现把成果和 NSNotificationCenter是专门供程序中不同类间的消息通信而设置的,使用起来极为 ...

  4. iOS: 消息通信中的Notification&KVO

    iOS: 消息通信中的Notification&KVO 在 iOS: MVC 中,我贴了张经典图: 其中的Model向Controller通信的Noification&KVO为何物呢? ...

  5. PHP消息队列用法实例分析

    这篇文章主要介绍了PHP消息队列用法,结合实例形式分析了PHP消息队列用于Linux下进程间通信的相关技巧,需要的朋友可以参考下   该消息队列用于linux下,进程通信 队列状态信息:具体参考手册

  6. 原生 Java 客户端进行消息通信

    原生 Java 客户端进行消息通信 Direct 交换器 DirectProducer:direct类型交换器的生产者 NormalConsumer:普通的消费者 MulitBindConsumer: ...

  7. ZeroMQ:云时代极速消息通信库

    ZeroMQ:云时代极速消息通信库(大规模|可扩展|低成本|高效率解决之道,大规模分布式|多线程应用程序|消息传递架构构建利器) [美]Pieter Hintjens(皮特.亨特金斯)著   卢涛 李 ...

  8. activity 和 生命周期: 消息通信

    实际上关于activity大概流程已经了解了,在深入的话方向应该是ams的处理操作和界面创建和view绘制.这些话题之后再谈,activity是一个gui程序,其中离不开的就是消息通讯,也就是在消息循 ...

  9. 消息通信库ZeroMQ 4.0.4安装指南

    一.ZeroMQ介绍 ZeroMQ是一个开源的消息队列系统,按照官方的定义,它是一个消息通信库,帮助开发者设计分布式和并行的应用程序. 首先,我们需要明白,ZeroMQ不是传统的消息队列系统(比如Ac ...

随机推荐

  1. 清空mysql的历史记录

    # vi ~/.mysql_history show tables; show databases; 清空里面的内容,并不用退出当前shell,就可以清除历史命令!!

  2. sprintf_s的使用

    int sprintf_s(char *restrict buffer, rsize_t bufsz,              const char *restrict format, ...); ...

  3. Android性能优化系列 + Android官方培训课程中文版

    Android性能优化典范 - 第6季 http://hukai.me/android-performance-patterns-season-6/   Android性能优化典范 - 第5季 htt ...

  4. ytu 1061: 从三个数中找出最大的数(水题,模板函数练习 + 宏定义练习)

    1061: 从三个数中找出最大的数 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 154  Solved: 124[Submit][Status][We ...

  5. android 入门-工序

    页面: 1.启动页 2.引导页 3.主页面 自定义控件: 轮播控件 轮播列表控件 弹出控件 加载控件 引导页控件 下拉刷新 上拉加载控件

  6. DTMF的原理分析

    转自:http://blog.csdn.net/wangwenwen/article/details/8264925 1. DTMF原理 DTMF(Double Tone MulitiFrequenc ...

  7. pthread_create传递参数

    转自:http://blog.csdn.net/yeyuangen/article/details/6757525 #include <iostream> #include <pth ...

  8. 在SharePoint2010中用out-of-box的方式自定制Application Pages(AccessDenied,Confirmation,Error,Login,RequestAccess,Signout,WebDeleted)

    在实际项目中需要对SharePoint2010中的AccessDenied页面进行自定制,于是乎上网搜索相关内容,经实际操作此方法可行,便以此文记录. 在SharePoint2010中,由于secur ...

  9. service里面弹出对话框

    如何在service里面弹出对话框先给一个需求:需要在service里面监听短信的接收,如果接收到短信了,弹出一个dialog来提示用户打开. 看看效果图:(直接在主桌面上弹出) service中弹出 ...

  10. Iterator

    hasNext() 方法是检查序列中是否还有元素. remove()方法是将迭代器返回的元素删除. List list = new ArrayList(); list .add(“a”); for(I ...