Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make UITableView fit to content's size

I have a UITableView (let's call it tbl_A) inside a table view cell whose height is dynamic and set by UITableViewAutomaticDimension. tbl_A's cell height is also dynamic, and I know tbl_A's data won't be too much. So I want tbl_A to be scroll disabled and its frame.size equals its content size. I tried to set tbl_A's frame.size.height = tbl_A.contentSize.height, unfortunately, the height is wrong.

By the way, I don't have to use UITableView to accomplish this task. I just want to a way to display all data. Any suggestions?

This is the effect I want to achieve: enter image description here

like image 232
YON Avatar asked Jan 27 '16 03:01

YON


People also ask

What is Uitableview in Swift?

A view that presents data using rows in a single column. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.1+ tvOS 9.0+

What is Indexpath in tableView Swift?

Swift version: 5.6. Index paths describe an item's position inside a table view or collection view, storing both its section and its position inside that section.


1 Answers

Simple ;)

override var intrinsicContentSize: CGSize {
    return contentSize
}
like image 124
Emad Avatar answered Sep 18 '22 07:09

Emad