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の実行を停止できるアイデアはありますか?