我使用如下代码订阅我自己的通知:
NSNotificationCenter.DefaultCenter.AddObserver("BL_UIIdleTimerFired", delegate {
Console.WriteLine("BaseFolderViewController: idle timer fired");
});要发送通知,请执行以下操作:
NSNotificationCenter.DefaultCenter.PostNotificationName("BL_UIIdleTimerFired", null);但是,只有当PostNotificationName(string sString, object anObject)的"anObject“参数不为空时,才能正确接收通知。
这是设计出来的吗?我必须传递一个对象吗?还是说这是个bug?我并不是真的想发送一个对特定对象的引用。
发布于 2011-10-01 00:20:29
我认为这是设计好的。苹果关于other overload (postNotificationName:object:userInfo:)的文档指出,userInfo参数可以为null。所以我认为其他两个不能为空。
"anObject“参数是发布通知的对象(发送者),也是可以从NSNotification类的object参数中检索的对象。
https://stackoverflow.com/questions/7612166
复制相似问题