iPhone通知の結果、「インスタンスに送信される認識されていないセレクター…」
-
12-10-2019 - |
質問
それを短くするために、私は以下を登録しています NSNotification
リスナー ClassA
(の 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);
}
の ClassB
(の中に tableView:didSelectRowAtIndexPath:
方法)私は持っています:
NSInteger row = [indexPath row];
NSString *stuff = [playlistArray objectAtIndex:row];
[[NSNotificationCenter defaultCenter] postNotificationName:@"playNotification" object:stuff];
それはすべて、次のようなエラーメッセージになります。
「インスタンスに送信された認識されていないセレクター」
の前に playSong
メソッドが呼び出されます。
誰かがここで私を助けてくれませんか?あるコントローラーから別のコントローラーに通知を投稿するとき、私は何を忘れていますか?
解決
あなたの @selector
必要です :
それが議論をする場合のキャラクター:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playSong:) name:@"playNotification" object:nil];
のインスタンス ClassA
行う いいえ に応答します playSong
セレクター、しかし彼ら 行う に応答します playSong:
セレクタ。
所属していません StackOverflow