先看api的文档:
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.
Parameters
-
。。。。
。。。。
notificationSender
-
The object whose notifications the observer wants to receive; that is, only notifications sent by this sender are delivered to the observer.
If you pass
nil, the notification center doesn’t use a notification’s sender to decide whether to deliver it to the observer.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(finishReadNFC:) name:@"NotificationFinishReadNFC" object:self];
发送notification端:
[[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationFinishReadNFC" object:self userInfo:[NSDictionary dictionaryWithObject:item forKey:NotificationKeySaveItem]];
参数放在userinfo里传送,而不是object
本文详细解析了NSNotification的使用方法,特别是如何通过addObserver方法设置观察者,接收特定发送者的通知。并展示了如何传递参数及正确使用NSNotification进行通信。

564

被折叠的 条评论
为什么被折叠?



