iOS 8中的UITextView问题:输入文本时文本视图不滚动。

3

我在iOS 8中遇到了问题,而之前的版本却是完美的。

我的文本视图大约有4行,在输入超过4行的文本时,文本视图会自动向上滚动,但在这种情况下在iOS8中不会滚动。

这是我的代码。

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

    NSString *updatedString = [textView.text stringByReplacingCharactersInRange:range withString:text];
    textView.text = updatedString;
    return NO;


}

谢谢您的提前帮助。

2个回答

5

尝试使用这段代码。

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

    NSString *updatedString = [textView.text stringByReplacingCharactersInRange:range withString:text];
    //textView.text = updatedString;
    [textView replaceRange:textView.selectedTextRange withText:text];
    return NO;

}

0
为了编辑UITextView的文本,您需要更新它的textStorage字段:
[_textView.textStorage beginEditing];

NSRange replace = NSMakeRange(10, 2); //enter your editing range
[_textView.textStorage replaceCharactersInRange:replace withString:@"ha ha$ "];

//if you want to edit the attributes
NSRange attributeRange = NSMakeRange(10, 5); //enter your editing attribute range
[_textView.textStorage addAttribute:NSBackgroundColorAttributeName value:[UIColor greenColor] range:attributeRange];

[_textView.textStorage endEditing];

祝你好运


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接