UITableView beginUpdates endUpdates使行闪烁

时间:2015-12-14 09:49:23

标签: ios iphone uitableview autolayout uitextview

我在自定义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闪现之外,一切正常。就细胞内容而言,我有图像和文本显示在其中。只有在图像的情况下,单元格才会闪烁。

1 个答案:

答案 0 :(得分:-1)

在更改框架之前,您必须致电beginUpdates

        [tableMessageDetail beginUpdates];
        // change cell attributes
        [tableMessageDetail endUpdates];