现在的位置: 首页 > 综合 > 正文

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

2018年08月06日 ⁄ 综合 ⁄ 共 641字 ⁄ 字号 评论关闭

实例化UITextVIew的类对象并将UITextView的实例对象的delegate设为self。

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:
哈哈。

抱歉!评论已关闭.