监听textView的属性的改变,用通知,代理不好用
2015-10-26 11:22
369 查看
添加通知
移除通知
监听文字改变,当不输入文字时,发微博的按钮是灰色的,当输入文字的时候按钮是橙色的。
/** * 添加textView */ - (void)setupTextView { // 1.添加 IWTextView *textView = [[IWTextView alloc] init]; textView.font = [UIFont systemFontOfSize:15]; textView.frame = self.view.bounds; [self.view addSubview:textView]; self.textView = textView; // 2.监听textView文字改变的通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange) name:UITextViewTextDidChangeNotification object:textView]; }
移除通知
- (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; }
监听文字改变,当不输入文字时,发微博的按钮是灰色的,当输入文字的时候按钮是橙色的。
/** * 监听文字改变 */ - (void)textDidChange { self.navigationItem.rightBarButtonItem.enabled = (self.textView.text.length != 0); }
相关文章推荐
- JS与Native交互初识
- 九度OJ 1189:还是约瑟夫环 (约瑟夫环)
- CentOS安装nodejs
- c++学习(一)
- 翻页条
- java socket 编程 服务器一直监听
- 第2篇 C# 基本数据结构
- 动态调用webservice 接口
- CentOS 6使用mutt+msmtp发送邮件
- 九度OJ 1189:还是约瑟夫环 (约瑟夫环)
- maven常用信息
- opencv2-第五章-图像金字塔
- 强大的网页性能测试工具--Speed Tracer
- 【Leetcode】之String to Integer (atoi)
- JAVA字符串格式化-String.format()的使用
- Webservice -- HttpCilent 访问Webservice 请求
- CLRS 8.2计数排序
- 微软算法100题25 查找连续最长的数字串
- 3D Touch
- Xcode 7 支持http请求info.plist设置