0

私は以下を使用して通知を送信しています:

[[NSNotificationCenter defaultCenter] postNotificationName:@"historyLoaded" object:jsonReturn];

そして、次を使用して通知を受け取ります。

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

次に、セレクターのメソッドは次のとおりです。

- (void) manageHistory: (NSNotification *) historyData{
     NSLog(@"this bit of code was run");
}

なぜか通知が届かない。アプリ内のどこからでも通知を送受信できますか?

4

2 に答える 2

1

objectパラメーターにpostNotificationは、通知を「送信」しているオブジェクトを入力するか、送信者が必ずしも指定されていない場合は nil を入力する必要があります。
何らかの情報を渡したい場合は、代わりに辞書を使用postNotificationName:object:userInfoして情報を配置する必要があります。userInfo

于 2011-08-15T10:51:47.687 に答える
0
[[NSNotificationCenter defaultCenter] addObserver:self 
       selector:@selector(manageHistory) name:@"historyLoaded" object:nil];

[[NSNotificationCenter defaultCenter] postNotificationName:@"historyLoaded" 
       object:nil userInfo:jsonReturn];

- (void) manageHistory: (NSNotification *) historyData{
         NSDictionary* _dict = historyData.userInfo;
         NSLog(@"Your information embedded to dictiuonary obj %@",_dict);
}

注:historyDataがpostNotificationNameのディクショナリオブジェクトであることを確認してください

于 2011-08-15T11:04:21.513 に答える