3

私のコードは次の場所でクラッシュしています:

[[NSNotificationCenter defaultCenter] postNotificationName:kgotNotification object:dictionary];

私の仮定は、オブザーバーが追加される前に通知を投稿していることです。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getItems:) name:kgotNotification object:nil];

通知を投稿する前に、アクティブなオブザーバーのリストを確認する方法はありますか?

4

1 に答える 1

2

次のようにする必要があります。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getItems:) name:kgotNotification object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:kgotNotification object:self userInfo:dictionary];

次に、getItems メソッド:

-(void)getItems:(NSNotification* )note
{
    NSLog(@"UserInfo: %@", note.userInfo);
}
于 2014-02-17T19:07:43.043 に答える