美文网首页
ios 官方文档 — 通知中心 NSNotification C

ios 官方文档 — 通知中心 NSNotification C

作者: 十萬個想知道 | 来源:发表于2017-07-31 10:46 被阅读13次

引用:官方Xcode文档和api参考

Foundation > NSNotificationCenter
中文版:ios官方文档 - 通知中心NSNotification Center 中文版

Class

NSNotificationCenter


Language
Swift
Objective-C

SDKs
iOS 2.0+
macOS 10.0+
tvOS 9.0+
watchOS 2.0+

On This Page
Overview
Symbols
Relationships


An NSNotificationCenter object (or simply, notification center) provides a mechanism for broadcasting information within a program. An NSNotificationCenter object is essentially a notification dispatch table.


Overview

Objects register with a notification center to receive notifications (NSNotification objects) using the addObserver:selector:name:object: or addObserverForName:object:queue:usingBlock: methods. Each invocation of this method specifies a set of notifications. Therefore, objects may register as observers of different notification sets by calling these methods several times.
Each running Cocoa program has a default notification center. You typically don’t create your own. An NSNotificationCenter object can deliver notifications only within a single program. If you want to post a notification to other processes or receive notifications from other processes, use an instance of NSDistributedNotificationCenter.

Symbols

Managing Notification Observers

- addObserverForName:object:queue:usingBlock:

Adds an entry to the receiver’s dispatch table with a notification queue and a block to add to the queue, and optional criteria: notification name and sender.

- addObserver:selector:name:object:

Adds an entry to the receiver’s dispatch table with an observer, a notification selector and optional criteria: notification name and sender.

- removeObserver:

Removes all the entries specifying a given observer from the receiver’s dispatch table.

- removeObserver:name:object:

Removes matching entries from the receiver’s dispatch table.

Posting Notifications

- postNotification:

Posts a given notification to the receiver.

- postNotificationName:object:

Creates a notification with a given name and sender and posts it to the receiver.

- postNotificationName:object:userInfo:

Creates a notification with a given name, sender, and information and posts it to the receiver.

Type Properties

(class) defaultCenter

.

Relationships

Inherits From
NSObject

相关文章

网友评论

      本文标题:ios 官方文档 — 通知中心 NSNotification C

      本文链接:https://www.haomeiwen.com/subject/gjbllxtx.html