TextView

来源:互联网 发布:表格怎么把相同的数据 编辑:程序博客网 时间:2024/05/21 10:31


最近在做一个需求的时候,出现了这样一个问题:textViewDidChange当程序中给UITextView赋值的时候,是不被调用的,如官方文档对该方法的说明:

Tells the delegate that the text or attributes in the specified text view were changed by the user.
The text view calls this method in response to user-initiated changes to the text. This method is not called in response to programmatically initiated changes.

如果必要在程序中给UITextView赋值又希望有相应的动作的话,我采用了一个替代方案:

1.在合适的地方注册一个系统的通知(注意name,系统定义的):

       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChangedExt:) name:UITextViewTextDidChangeNotification object:nil];

2.实现textChangedExt:

- (void)textChangedExt:(NSNotification *)notification

{

}


ios TextView自动滚动到最后一行

[_textView scrollRectToVisible:CGRectMake(0, _textView.contentSize.height-15, _textView.contentSize.width, 10) animated:YES];

原创粉丝点击