14

簡単に言うと、次のNSNotificationリスナーをClassA(in viewDidLoad)に登録しています。

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

で宣言されたセレクターがありClassA.hます:

- (void)playSong:(NSNotification *) notification;

そして、実装は次のようになります。

- (void)playSong:(NSNotification *) notification {
    NSString *theTitle = [notification object]; 
    NSLog(@"Play stuff", theTitle);
}

(方法ClassBtableView:didSelectRowAtIndexPath:)私は持っています:

NSInteger row = [indexPath row];
NSString *stuff = [playlistArray objectAtIndex:row];
[[NSNotificationCenter defaultCenter] postNotificationName:@"playNotification" object:stuff];

それはすべて、次のようなエラーメッセージで終わります:

「認識できないセレクターがインスタンスに送信されました」

playSongメソッドが呼び出される前。

誰かここで私を助けてくれませんか? あるコントローラーから別のコントローラーに通知を投稿するときに、何を忘れていますか?

4

1 に答える 1

42

引数を取る場合は@selector、文字が必要です。:

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

のインスタンスはセレクターに応答しClassAませんが、セレクターに応答します。playSongplaySong:

于 2010-12-24T00:02:20.323 に答える