iOS NSNotificationCenter详解
来源:互联网 发布:java服务器的书籍 编辑:程序博客网 时间:2024/06/05 08:09
作用:NSNotificationCenter是专门供程序中不同类间的消息通信而设置的.
注册通知:即要在什么地方接受消息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mytest:) name:@" mytest" object:nil];
参数介绍:
addObserver: 观察者,即在什么地方接收通知;
selector: 收到通知后调用何种方法;
name: 通知的名字,也是通知的唯一标示,编译器就通过这个找到通知的。
发送通知:调用观察者处的方法。
[[NSNotificationCenter defaultCenter] postNotificationName:@"mytest" object:searchFriendArray];
参数:
postNotificationName:通知的名字,也是通知的唯一标示,编译器就通过这个找到通知的。
object:传递的参数
1.简单实例
- (void)viewDidLoad{ [super viewDidLoad]; // 1.监听通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChange) name:UITextFieldTextDidChangeNotification object:self.accountField]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChange) name:UITextFieldTextDidChangeNotification object:self.pwdField]; }<span style="color:#FF0000;">//2.</span>- (void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self];}<span style="color:#FF0000;">/** * 3.文本框的文字发生改变的时候调用</span> */- (void)textChange{ // 控制按钮的状态// if (self.accountField.text.length && self.pwdField.text.length) {// self.loginBtn.enabled = YES;// } else {// self.loginBtn.enabled = NO;// } self.loginBtn.enabled = (self.accountField.text.length && self.pwdField.text.length);}
0 0
- iOS NSNotificationCenter详解
- iOS NSNotificationCenter详解
- iOS NSNotificationCenter 使用详解
- iOS开发之NSNotificationCenter详解
- iOS NSNotificationCenter 使用姿势详解
- iOS NSNotificationCenter 使用姿势详解
- iOS NSNotificationCenter 使用姿势详解
- iOS NSNotificationCenter 使用姿势详解
- iOS NSNotificationCenter 使用姿势详解
- iOS NSNotificationCenter 使用姿势详解
- iOS NSNotificationCenter 使用姿势详解
- iOS开发-进阶:NSNotificationCenter 使用姿势详解
- iOS NSNotification和NSNotificationCenter的详解
- ios NSNotificationCenter
- IOS NSNotificationCenter
- [IOS] NSNotificationCenter
- IOS:NSNotificationCenter
- IOS NSNotificationCenter
- Unity3d中的属性(Attributes)整理
- 如何用FreeMarker生成静态页面
- 乐视揭秘Android5.0手机APP安装失败真相
- 统计学习笔记(1)——统计学习方法概论
- 工厂方法模式
- iOS NSNotificationCenter详解
- Server Tomcat v7.0 Server at localhost failed to start.
- 2叉树遍历的递归实现-使用c++模板
- swift函数式编程-函数基础
- Android Studio中文字体显示乱码
- class_create() and device_create()
- 《Effective java》读书记录-第13条-使类和成员的可访问性最小化
- 统计学习笔记(2)——感知机模型
- 无定位父元素时offsetParent为body,但是offsetTop/offsetLeft计算距离从html开始