IOS NSNotificationCenter 通知的使用

1.注册通知

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

-(void)notify

{

  NSLog(@"notify");

}

2.触发通知

 [NSNotificationCenter defaultCenter] postNotificationName:@"myNotify" object:nil];

 

3.移除通知
  [NSNotificationCenter defaultCenter] removeObserver:self name:@"myNotify" object:nil];

 

如果使用[NSNotificationCenter defaultCenter] removeObserver:self ] 也就是没有指定 name的话,那跟self有关的所有的通知都会被移除掉,如果指定了name的话,只会移除跟name匹配的通知。

 

其中  object  是可以附带传递的参数。

 

 

posted on 2014-05-19 19:59  景树园  阅读(178)  评论(0编辑  收藏  举报

导航