iOS 廣播、kvo、NSNotificationCenter (通知中心)

通知中心用的不是很熟。

只知道一個簡單的信息發送,信息接受。

       //信息發送

[[NSNotificationCenter defaultCenter] postNotificationName:@"hehe" object:nil userInfo:@{[NSString stringWithFormat:@"%ld",count]:@"key"}];

    //註冊通知接收者

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

  //退出的時候移除 

 [[NSNotificationCenter defaultCenter] removeObserver:self];

   // 信息接收

- (void)NSNotificationCenterMethod :(NSNotificationCenter *)userinfo {

    NSLog(@"userinfo :%@",userinfo);

}

後續再補充...
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章