简体   繁体   中英

How to change layout of a UITableViewCell with a UIStackView

I have a custom UITableViewCell with a vertical UIStackView. The stack view in-turn has 2 UILabels, one of it is hidden by default. How to change the height of the cell to show both labels in the stack view properly when the second label is unhidden. On a button click when i show the second label, it tries to show both label with the same height overlapping each other, however when i scroll the view up and down, it re-renders it ok.

I tried to call SizeToFit and LayoutIfNeeded with no help. How do i change the height of the row/cell to show both labels in the stackview to look proper?

具有stackview和第二个标签隐藏的单元格 具有stackview和未隐藏第二个标签的单元格

单击按钮时,将显示标签2nd,您应该重新加载表格视图,或者精确地重新加载单元格,单元格的高度将发生变化,单元格将被重新渲染

单击显示两个标签的按钮后reloadRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation)尝试使用reloadRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation)重新加载该行。

You can call

tableView.beginUpdates()
tableVIew.endUpdates()

After tap on button, and your cell change height. It solution is compatible with animation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM