多个对象订阅 NSNotification (Objective-c)
我有一个订阅 MyNSNotification
的 Objective-c 类 MyClass
。我的应用程序中有多个 MyClass
实例。因此多个对象会收到通知。 有没有办法“过滤”特定对象的通知?
我想在选择器中进行检查。我只是不确定如何设置它。
I have an Objective-c class MyClass
that subscribes to MyNSNotification
. There are multiple instances of MyClass
in my application. Hence multiple objects receive the notification. Is there a way to "filter" notifications for a particular object?
I imagine doing a check in the selector. I'm just not sure how to set it up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 userInfo 来发出通知。接收一个检查 userInfo 以确定此通知是否针对此处。有时足以知道谁发送了通知。为此使用对象属性。请参阅类参考 http:// developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSNotification_Class/Reference/Reference.html
Use userInfo for that purpose issuing notification. Recieving one check userInfo to decide if this notification targeted here or not. Sometimes enough to know who sent notification. Use object property for that. Consult class reference http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSNotification_Class/Reference/Reference.html