2011年2月28日月曜日

NSNotificationの登録

//登録(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"];
}