iphone - NSNotification addObserver :? 中的参数 `object` 是什么

标签 iphone nsnotificationcenter

我的一个名为 Message.m 的类正在发布一个带有对象 sentObject 的通知如下

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 将作为接收者来捕获通知,如下

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(dataReloaded:) 
                                             name:@"reloadDuringSave" 
                                           object:nil];

对于发布通知,userInfo可以是nil或者可以是object (如本例中 sentObject 作为 NSDictionary 类型)。

问题:

object 的其他参数是什么在addObserver方法?他们可以是 除 nil 以外的任何内容,如果是的话又怎样?

最佳答案

addObserver”的“object”参数是可选的过滤器。发布通知后,您可以为通知的​​发送者设置一个对象,然后只会收到有关该发送者的事件的通知。如果设置为“nil”,您将收到此类类型的所有通知(无论是谁发送的)。

关于iphone - NSNotification addObserver :? 中的参数 `object` 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11643866/

相关文章:

ios - 如何检查 ios 中的互联网连接?

ios - 今天扩展 UIWebView

ios - 如何在 Swift 中使用 NSTimer 和 NSNotificationCentre 更新 UITableViewCells

ios - 如何设置 UNNotificationRequest 自定义重复间隔?

objective-c - Cocoa 从子类中的子类发布 NSNotification

iphone - Safari 中奇怪的 SPAN 元素呈现(在 iPhone 上)

iPhone:来自网络的缓存个人资料图像 - 如何找出远程图像已更改?

ios - 如果不关闭sqlite数据库是否可能丢失数据?

iphone - 添加 TabBar 元素

iphone - 我们可以将属性/合成到 sqlite3 * 数据库对象吗?