我想创建一个 NSNotification 对象,如下所示:
NSNotification *obj=[[NSNotification alloc]init];
但是当我像这样创建时,我收到一个异常“NSConcreteNotification init:不允许”。
我应该如何解决这个问题?
来自NS通知 http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSNotification_Class/Reference/Reference.html文档:
您可以使用类方法创建通知对象notificationWithName:object: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSNotification_Class/Reference/Reference.html#//apple_ref/occ/clm/NSNotification/notificationWithName:object: or notificationWithName:object:userInfo: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSNotification_Class/Reference/Reference.html#//apple_ref/occ/clm/NSNotification/notificationWithName:object:userInfo:。但是,您通常不会直接创建自己的通知。 NSNotificationCenter 方法postNotificationName:object: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/Reference/Reference.html#//apple_ref/occ/instm/NSNotificationCenter/postNotificationName:object: and postNotificationName:object:userInfo: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/Reference/Reference.html#//apple_ref/occ/instm/NSNotificationCenter/postNotificationName:object:userInfo:让您无需先创建通知即可方便地发布通知。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)