我在自定义UITextView
中有UITableViewCell
。在扩展UITextView时,我希望UITextView
下方的子视图按其高度降低,并且还会增加行高。为此,我正在做:
- (void)textViewDidChange:(UITextView *)textView
{
int numLines = textView.contentSize.height/textView.font.lineHeight;
if(numLines < 6)
{
CGRect frame = textView.frame;
frame.size.height = textView.contentSize.height;
textView.frame = frame;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(int)textView.tag inSection:0];
MessageDetailCell *cell = [tableMessageDetail cellForRowAtIndexPath:indexPath];
cell.txtReplyHeightConstraint.constant = textView.frame.size.height;
[cell updateConstraintsIfNeeded];
[cell setNeedsLayout];
[cell layoutIfNeeded];
[tableMessageDetail beginUpdates];
[tableMessageDetail endUpdates];
}
}
除beginUpdates
endUpdates
使UITableViewCell
闪现之外,一切正常。就细胞内容而言,我有图像和文本显示在其中。只有在图像的情况下,单元格才会闪烁。
答案 0 :(得分:-1)
在更改框架之前,您必须致电beginUpdates
。
[tableMessageDetail beginUpdates];
// change cell attributes
[tableMessageDetail endUpdates];