简体   繁体   中英

Set UITableViewCell dynamically based on child UITableView contentSize Swift

I have an UITableView (aka. ParentTableView) with multiple UITableViewCell's. Each UITableViewCell contains some labels and an UITableView (aka. ChildTableView).

The ChildTableView's rows have different amounts of UITableViewCells.

There is two things I need help to figure out.

1. The height of the ChildTableView should be the height of its contents. So there should be no scroll on this tableview. It's basically just a list.

2. Set the ParentTableView's row height to: (default height + ChildTableView's calculated height from question 1)

After tableView finishes loading cells ( gets its content ) update the Frame of the TableView with the Content Size.

so after reloadData :

var bounds = tableView.bounds
bounds.size.height = tableView.contentSize.height
// You can add anything to the height now with bounds.size.height += something
tableView.bounds = bounds

You can also explicitly disable the scrolling with scrollEnabled = false

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