通知NSNotificationCenter

 

注意:接受通知要写在 viewDidLoad 方法里面

 

取得系统全局的唯一广播站

NSNotificationCenter *notification = [NSNotificationCenter  defaultCenter];

设置广播的名字和 参数等。。。

[notification postNotificationName:@” ChangeTheme” object:self  userInfo:自己要传的的参数];

给系统ChangeTheme频段发送一个广播

频段的名字是ChangeTheme  频段的名字不能重复

 

注册成为ChangeTheme这个频段的听众

NSNotificationCenter *notification = [NSNoyification  defaultCenter];

Notification addobserver:self  selector:@selector(recvBcast:)  name:@“ChangeTheme”

接受广播 ChangeTheme

一旦有广播了就让系统自动调用 self里面的recvBCast: 函数

 

-(void) recvBCast:(NSNotification *)notification

{

  recvBCast:不是我们调用的 是iOS系统调用

  NSString *name = [notify name];

  Name其实就是ChangeTheme

  Id  obj = [notify object];

  Obj就是所在的viewcontroller

  NSdictionary *dict = [notify userInfo]; 

  Dict 就是传过来的值

}

posted @ 2015-10-10 17:16  上官元空  阅读(184)  评论(0编辑  收藏  举报