ios - UITableViewCell layout not updating until cell is reused -


i have uitableview fill autosizing cells. uitableview setup simple:

    tableview.estimatedrowheight = 70     tableview.rowheight = uitableviewautomaticdimension 

exactly apple recommends here: https://developer.apple.com/library/content/documentation/userexperience/conceptual/autolayoutpg/workingwithself-sizingtableviewcells.html

to enable self-sizing table view cells, must set table view’s rowheight property uitableviewautomaticdimension. must assign value estimatedrowheight property. both of these properties set, system uses auto layout calculate row’s actual height.

when configuring cell disable/enable constraints achieve needed look. that’s things interesting. cell layout not updated until cell reused. literally. can call layoutifneeded(), setneedslayout(), layoutsubviews() or other method there is, there no way force cell update layout.

all other aspects work pretty good: labels change text, hide/unhide views, layout stuck until cell reused.

question: causes , how avoid behavior?

in case, issue caused estimatedrowheight.

simply removing line

tableview.estimatedrowheight = 70 

fixed problems. cell updated layout , fixed issues.

but, likely, you’re going trouble, cell’s height being set 43.5 points. log filled auto layout errors, include line this

<nslayoutconstraint:0x600000097570 'uiview-encapsulated-layout-height' uitableviewcellcontentview:0x7fd4ee511d20.height == 43.5   (active)> 

apparently, if won’t provide estimatedrowheight, table view puts 43.5 points height constraint on cell’s content view, , if cell’s “internal” height not match (and probability of 99.99%), it’s going put errors in log.

how avoid error? don’t know yet. post question that, , find answer, provide link in question.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -