什么是NSNotification? [英] What is NSNotification?

查看:122
本文介绍了什么是NSNotification?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能解释一下NSNotificationCenter的重要性吗?

Can anybody explain the importance of NSNotificationCenter?

在哪里使用它们?

有什么区别在NSNotificationCenter与AppDelegate之间?

What is the difference between NSNotificationCenter vs. AppDelegate?

推荐答案

Apple在Cocoa库中提供了一个名为NSNotificationCenter的观察者模式。

Apple has provided an Observer Pattern in the Cocoa library called the NSNotificationCenter.

基本思想是监听器使用某种预定义协议向广播公司注册。在稍后的某个时刻,广播公司被告知通知所有听众,它在每个听众上调用一些函数并传递某些参数。这允许在不必彼此了解的两个不同对象之间传递异步消息,他们只需要了解广播公司。

The basic idea is that a listener registers with a broadcaster using some predefined protocol. At some later point, the broadcaster is told to notify all of its listeners, where it calls some function on each of its listeners and passes certain arguments along. This allows for asynchronous message passing between two different objects that don't have to know about one-another, they just have to know about the broadcaster.

您可以找到更多有关它的详细信息: http://numbergrinder.com/node/32

You can find more details about it here: http://numbergrinder.com/node/32

Application Delegate是一个对象,它在UIApplication对象达到某些状态时接收通知。在许多方面,它是一个专门的一对一观察者模式。

The Application Delegate is an object which receives notifications when the UIApplication object reaches certain states. In many respects, it is a specialized one-to-one Observer pattern.

您可以在这里阅读更多相关信息:什么是AppDelegate以及如何知道何时使用它?

You can read more about it here: What is the AppDelegate for and how do I know when to use it?

这篇关于什么是NSNotification?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆