IPhone之NSNotificationCenter

来源:互联网 发布:ie9 js兼容性问题 编辑:程序博客网 时间:2024/05/21 06:31

转载自:http://blog.sina.com.cn/s/blog_4adf31ea0100npdj.html


1、自定义消息

定义一个方法

 

-(voidupdate

{

}

 

 

对象注册,并关连消息

 

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(update) name:@"update" object:nil] 

 

调用

 

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

 

 

2、注册键盘升启关闭消息

 

//键盘升起 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

//键盘降下
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];




另:加上我的通知实现:







原创粉丝点击