How to automatically resize a UITableView according to the amount of content in it?
I want to do something like what I can do with a UiTextView:
MyTextView.sizeToFit()
How to automatically resize a UITableView according to the amount of content in it?
I want to do something like what I can do with a UiTextView:
MyTextView.sizeToFit()
You need to get the height of the cell, ask for the array that you use as the dataSource of the count
and then set the size in the frame, here's an idea:
var tamanhoCell = tableView.rowHeight
var count = seuArray.count
tableView.frame = CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y, tableView.frame.size.width, tamanhoCell * count);
I still think your question does not make much sense, because TableView was meant to accommodate the items in there without increasing its height, but good luck!
Simple, just insert this code into your viewDidLoad:
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 76
In the first line, it will scale automatically. In the second, you estimate the most used height. In theory, you only need the first, but I recommend using both.
Hugs.