您的位置:首页 > 产品设计 > UI/UE

iPhone开发--UITextView中的文字改变时触发的事件

2015-02-09 09:54 316 查看
实例化UITextVIew的类对象并将UITextView的实例对象的delegate设为self。

[cpp] view
plaincopy

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方法来监听文字改变的消息了。

[cpp] view
plaincopy

- (void)textViewDidChange:(UITextView *)textView {

NSLog(@"textViewDidChange:%@", textView.text);

}

一定要记得在头文件中导入UITextViewDelegate哦。

附加:
该代理还实现了以下几种监听事件

– textViewShouldBeginEditing:

– textViewDidBeginEditing:

– textViewShouldEndEditing:

– textViewDidEndEditing:

哈哈。

转载:http://blog.csdn.net/zcl369369/article/details/7552003
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐