0
NSNotificationを使用してViewControllers間で値を渡していますが、値が渡されず、ブレークポイントを使用して何がうまくいかないかを確認すると、受信通知セレクタメソッドが呼び出されていないことがわかりました。 には、以下の私がNSNotificationセレクタメソッドが呼び出されない
AViewController.m
[[NSNotificationCenter defaultCenter] postNotificationName:@"speciality" object:nil userInfo:[specialityIdArray objectAtIndex:indexPath.row]];
BViewCOntroller.m
-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveSpecialityId:) name:@"speciality" object:nil];
}
-(void)receiveSpecialityId:(NSNotification *)notificaton
{
NSString *selectedServiceString=[[notificaton userInfo] valueForKey:@"service"];
_specialtiyId = selectedServiceString;
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"service" object:nil ];
}
私は BViewController
にAViewControllerから値を渡すしようとしていますが書かれているどのようなコードであります私はすべてのディスカスを読んだシオンはこの同じ問題に以前に行われ、それらのどれもviewDidAppear
で
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveSpecialityId:) name:@"speciality" object:nil];
を追加
'AVViewController.mの前に' BViewCOntroller.m'が初期化されていることを確認してください。 – iSashok
新しいコントローラがviewWillAppearに達する前に通知が送信される可能性があります。 通知を送信するために使用したメソッドと2つのコントローラをロードするコードを投稿できますか? –