什么是对象的参数,nsnotification addObserver [英] what is param for object, nsnotification addObserver
问题描述
我的一个名为Message.m的类正在发布一个带有对象 sentObject
的通知,如下所示
One of my class named Message.m is posting a notification with an object sentObject
as below
NSDictionary *sentObject = [NSDictionary dictionaryWithObjectsAndKeys:draftData.arr,@"data", nil];
//Post notification to inform a receiver to reload data
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadDuringSave" object:self userInfo:sentObject];
DraftData.m将成为接收通知的接收方,如下所示
DraftData.m will be be the receiver to catch the notification as follow
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(dataReloaded:)
name:@"reloadDuringSave"
object:nil];
对于发布通知, userInfo
可以 nil
或者可以是对象
(例如 sentObject
作为类型本例中 NSDictionary
。
For posting notification, userInfo
can be nil
or can be an object
(like sentObject
as type of NSDictionary
in this example).
===> 问题: object
的其他参数在 addObserver
方法。它可以是除了nil以外它们是什么...
===> Question : what are other params for object
in addObserver
method. Can it be other than nil and what are they..
推荐答案
将object参数改为 addObserver 是一个可选的过滤器。您可以将其设置为通知的发件人,然后只会通知该发件人的事件。如果设置为nil,您将收到此类型的所有通知(无论是谁发送的)。
That "object" parameter to "addObserver" is an optional filter. You can set it to the sender of the notification, and will then only be notified of that sender's events. If set to "nil" you will get all notification of this type (regardless who sent them).
这篇关于什么是对象的参数,nsnotification addObserver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!