我无法在 NSNotificationCenter 中执行选择器方法 receiveChatText,我想知道问题是否是因为 NSNotification postNotificationName 在 AppDelegate.m 中但 NSNotificationCenter 在 ViewController.m 中?IE 可以 postNotificationName 知道 NSNotificationCenter 在另一个 viewController 文件中还是我需要告诉它的东西?
在 viewController.m 我有
-(id)init
{
self = [super init];
if(self){
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveChatText:)
name:ChatMessageReceived
object:nil];
return self;
}
- (void)receiveChatText:(NSNotification *)note {
NSLog(@"received chat text");
}
在顶级 AppDelegate.m 文件中,我有以下内容:
-(void) didReceiveMessage {
[[NSNotificationCenter defaultCenter] postNotificationName:ChatMessageReceived
object:nil
userInfo:nil];
}
有什么想法可以阻止在调用 didReceiveMessage 时执行 receiveChatText 吗?