实例化UITextVIew的类对象并将UITextView的实例对象的delegate设为self。
– textViewShouldBeginEditing:
– textViewDidBeginEditing:
– textViewShouldEndEditing:
– textViewDidEndEditing:
- m_contentTextField = [[[UITextView alloc] init] autorelease];
- m_contentTextField.frame = CGRectMake(0, 0, 320, 90) ;
- m_contentTextField.backgroundColor = [UIColor whiteColor] ;
- m_contentTextField.font = [UIFont systemFontOfSize:14];
- m_contentTextField.delegate = self ;
- [m_contentTextField becomeFirstResponder];
之后通过UITextViewDelegate的方法中的textViewDidChange方法来监听文字改变的消息了。
- - (void)textViewDidChange:(UITextView *)textView {
- NSLog(@"textViewDidChange:%@", textView.text);
- }
一定要记得在头文件中导入UITextViewDelegate哦。
附加:
该代理还实现了以下几种监听事件– textViewShouldBeginEditing:
– textViewDidBeginEditing:
– textViewShouldEndEditing:
– textViewDidEndEditing:
哈哈。
转载:http://blog.csdn.net/zcl369369/article/details/7552003
本文介绍如何使用UITextView并在Swift中设置代理(self)来监听文本框内的文本变化。通过实现UITextViewDelegate协议中的textViewDidChange方法,可以实时获取到文本框内输入内容的变化。

1173

被折叠的 条评论
为什么被折叠?



