陈斌彬的技术博客

Stay foolish,stay hungry

别错误使用 [NSNotificationCenter defaultCenter] 的 Object

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.

  • (void)addObserver:(id)notificationObserver selector:(SEL)notificationSelector name:(NSString *)notificationName object:(id)notificationSender 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.

很明显,此object 是用于过滤Notication的,只接收指定Sender所发的Notification

[[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

Resource Reference