UITextView 的 UITableView 和滚动问题

Posted

技术标签:

【中文标题】UITextView 的 UITableView 和滚动问题【英文标题】:UITableView and Scroll issue with UITextView 【发布时间】:2015-01-13 22:13:19 【问题描述】:

我在 TableView 中有 UITextView,我正在使用 UITableViewAutomaticDimension 来计算 单元格高度。

但问题是,一旦我开始在 UITextView 中输入,TableView 开始上下晃动!

在 textViewDidChange 事件中我的代码下方:

ImageDescriptionTableViewCell *cell = (ImageDescriptionTableViewCell *)textView.superview.superview ;
NSInteger index = [self.TableViewController indexPathForCell:cell].row;
[self.cellTextArray replaceObjectAtIndex:index withObject:textView.text];

[self.TableViewController beginUpdates];
[self.TableViewController endUpdates];

表格视图单元格中的约束:

[self.ImageDetails addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[flebImageDetails(300@999)]" options:0 metrics:nil views:@@"ImageDetails":self.ImageDetails]];

[self.ImageDetails addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[ImageDetails(>=30)]" options:0 metrics:nil views:@@"ImageDetails":self.ImageDetails]];

[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[ImageDetails]-|" options:0 metrics:nil views:@@"ImageDetails":self.ImageDetails]];

[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-5-[ImageDetails]-5-|" options:0 metrics:nil views:@@"ImageDetails":self.ImageDetails]];

请帮助我解决 1 弱前的问题。

【问题讨论】:

【参考方案1】:

我认为您不需要文本更改事件中的 beginUpdates 和 endUpdates。仅当您要修改(即添加、删除等)多行并希望它们作为一个单元进行动画处理时才需要这些。更新文本字段不需要它们。

【讨论】:

以上是关于UITextView 的 UITableView 和滚动问题的主要内容,如果未能解决你的问题,请参考以下文章

如何将 UITextView 添加到 UITableView 详细信息

将 UITextView 放在 UITableView 页脚中

UITableview swift中的UITextview高度

UITextView 的建议位于 UITableView 的浮动标题下

选择 UITableView 行时使用特定信息填充 UITextView

Swift 循环遍历 UITableView 中的所有 UITextView