簡體   English   中英

UITableView beginUpdates endUpdates使行閃爍

[英]UITableView beginUpdates endUpdates makes the row flash

我在自定義UITableViewCell有一個UITextView 在擴展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閃存之外,一切正常。 就細胞內容而言,我有圖像和文本顯示在其中。 僅在圖像的情況下,單元格閃爍。

您必須在更改框架之前調用beginUpdates

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM