![](/img/trans.png)
[英]UITableView beginUpdates() and endUpdates() clarification
[英]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.