NSNotificationCenter:在2个类之间传递通知
我有两节课。
class1 通过网络获取一些信息。当其中一个信息到来时,class1 必须向 class2 发送通知。
我明白了,所以我必须将其放入
[[NSNotificationCenter defaultCenter] postNotificationName:at"anyUserNotification" object:class2];
class1
[[NSNotificationCenter defaultCenter] addObserver:self selector:atselector(anyInteraction:) name:dontKnowTheSense object:dunno2];
我是否理解了 postnotification 中的对象:class2 对吗? 如果是:是否可以进行匿名通知,以便发送班级不知道哪些班级以及有多少班级正在收听? 或者 - 至少我这么认为,我对整个通知的理解是否错误?
除了通知之外,我不需要传递任何数据,但在一种情况下,传递枚举会很有帮助
,所以有人可以帮助我吗?
顺便说一句:我找不到在这台 Windows 电脑上发布 at 的方法,我不知道为什么它没有缩进代码,我想我做了 4 个空格
i have 2 classes.
class1 gets some information through the net. when one of these informations comes, class1 has to send a notification to class2.
i understood it so that i have to put
[[NSNotificationCenter defaultCenter] postNotificationName:at"anyUserNotification" object:class2];
into class1
[[NSNotificationCenter defaultCenter] addObserver:self selector:atselector(anyInteraction:) name:dontKnowTheSense object:dunno2];
have i understood the object:class2 in the postnotification right ?
if yes: is it possible to make an anonymious notification, so that the sending class must not know, which and how many classes are listening ?
or - at least i think so, have i understood the whole notification incorrect ?
besides the notification i dont need to pass any data, but in one case it would be helpful to pass an enum
so, could anybody please help me ?
btw: i cant find a way to post an at on this windows-pc and i dont know, why it did not indent the code, i think i made 4 spaces
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Object 不是强制参数,您可以将其设置为 nil 或发送通知消息的对象。
监听时,您可以过滤为仅对特定发件人发送的通知执行某些操作。
您可以使用 userInfo: 参数在字典中传递数据。
可以吗?
Object is not a mandatory argument you can set it to nil or the object sending the notification message.
When listening you can filter to only do something for notification sent by a specific sender.
And you can pass your data in a dictionnary with userInfo: argument.
Is it Ok with that ?