iphone - NSNotification 的目的是什么?

发布于 2024-09-30 18:48:23 字数 165 浏览 3 评论 0原文

  1. 你能解释一下什么是 NSNotification 的目的,以及 我可以在哪些情况下使用 它?

  2. 通知是否调用所有类 在应用程序中,或者它是否调用 特定的类,通过传递 委托?

  3. 是否可以创建1 通知,并在 多个类?

  1. Can you please explain what is the
    purpose of the NSNotification, and
    what are some situations I could use
    it?

  2. Does a notification call all classes
    in the app, or does it call a
    specific class, by passing a
    delegate?

  3. Is it possible to create 1
    notification, and receive it on
    multiple classes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

星光不落少年眉 2024-10-07 18:48:23
  1. 使用 NSNotification,您可以通知多个对象有关某个事件的信息,并且您可以做到这一点,而不必关心哪些对象以及其中有多少对象正在侦听该通知。

    使用

  2. NSNotification 传递通过 NSNotificationCenter 对象,该对象负责从创建通知的对象(使用 postNotification:函数系列)获取通知,并将它们发送到注册监听特定通知的对象(要接收通知对象必须在 NSNotificationCenter 中注册,使用addObserver: 函数)

  3. 通知可以被多个对象观察 - 所有这些对象都必须在 NSNotificationCenter 中注册,

  1. Using NSNotification you can notify multiple objects about some event and you can do that not caring about which objects and how many of them are listening for that notification.

  2. NSNotification passes through NSNotificationCenter object that is responsible for getting notifications from objects who create them (using postNotification: functions family) and sending them to the objects who are registered to listen to specific notification (to receive notification object must register in NSNotificationCenter using addObserver: functions)

  3. Notification can be observed by multiple objects - all of them must just register in NSNotificationCenter,

爱人如己 2024-10-07 18:48:23

NSNotification 对象封装信息,以便可以通过 NSNotificationCenter 对象将其广播到其他对象。

NSNotification 对象(称为通知)包含名称、对象和可选字典。该名称是标识通知的标签。该对象是通知的发布者想要发送给该通知的观察者的任何对象(通常是发布通知的对象)。该字典存储其他相关对象(如果有)。 NSNotification 对象是不可变的对象。

NSNotification objects encapsulate information so that it can be broadcast to other objects by an NSNotificationCenter object.

An NSNotification object (referred to as a notification) contains a name, an object, and an optional dictionary. The name is a tag identifying the notification. The object is any object that the poster of the notification wants to send to observers of that notification (typically, it is the object that posted the notification). The dictionary stores other related objects, if any. NSNotification objects are immutable objects.

趁微风不噪 2024-10-07 18:48:23

1:您是否阅读过 通知编程主题 ?

2:观察者应该注册一个通知

3:是的,多个对象可以观察同一个通知

1: Have you read Notification Programming Topics ?

2: Observer should be registred for a notification

3: Yes, several object can observe the same notification

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文