NSNotificationCenter消息通信(KVO)

NSNotificationCenter是程序不同类间的消息通信.

注册消息通知:

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

addObserver: 注册通知

selector: 收到通知后调用何种方法;

name: 通知的名字(唯一标示)。

发送消息通知:

 [[NSNotificationCenter defaultCenter] postNotificationName:@"mthMsg" object:obj];
  postNotificationName:消息的名称  
//键盘注册通知
1
//键盘升起 2 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 3 //键盘降下 4 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

 

posted @ 2013-12-13 11:52  wangzhenxiang  阅读(202)  评论(0编辑  收藏  举报