//登録(didloadなどで)
[[NSNotificationCenter defaultCenter] addObserver:class
selector:@selector(yobimethod:) name:@"notificationName" object:nil];
/*class内*/
-(void)yobu{//呼び出し※引数はなくてもOK
NSDictionary *userInfo =
[NSDictionary dictionaryWithObject:obj forKey:@"objkey"];
[[NSNotificationCenter defaultCenter] postNotificationName:
@"notificationName" object:nil userInfo:userInfo];
}
//呼び出されるメソッド
-(void)yobimethod:(NSNotification *)notification{
NSString*key = [[notification userInfo] objectForKey:@"objkey"];
}
2011年2月28日月曜日
NSNotificationの登録
2011年1月6日木曜日
NSNotificationの解除
NSNotificationを登録したらdeallocで以下を入れておく。
登録したNotificationを全て削除できる。便利。
notification名を指定して削除もできる。
一つだけ削除するとか何か意味があるんだろうか…?
登録したNotificationを全て削除できる。便利。
[[NSNotificationCenter defaultCenter] removeObserver: self];
notification名を指定して削除もできる。
一つだけ削除するとか何か意味があるんだろうか…?
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"notificationname" object:nil];
登録:
投稿 (Atom)