How to set auto height for UITableView?

I've added TableView to my Controller and set the next:

The priority of my height is equal to 250(Low).

So, how can I make that even I have 10 rows, my UITableView will show fully and height will change automatically?

Now I have a scroll in my UITableView. How to fix it?


You can add a UIScrollView. On top of it add a UITableView with scrollingEnabled = false.

Knowing the number of cells in the tableView and the height of each row, you can calculate the UITableView total height and set the scrollView's contentSize accordingly.

If you are trying to keep the height of the tableview constant regardless of whether you have 1 cell or 10 cells, then you need to make your cell height be dynamic, and change it based on the number of cells you have (height = available_height / numberOfCells).

Usually cell height is fixed, or it is dynamic like the cells in the Messages app, and that is done by manipulating:

- tableView:heightForRowAtIndexPath:

- tableView:estimatedHeightForRowAtIndexPath:

If you are not trying to keep the tableView a constant height, then you should still use the above methods to make the cells take up the appropriate amount of space to allow the tableView not to need scrolling, and then you will have to readjust the size of the tableView to pull the bottom up.

AutoLayout won't do this for you automatically, as far as I know. There are tricks to make AutoLayout be more aware of the size of your objects, such as adding


That might be overkill for what you are doing.

Need Your Help

list: No such file or directory

android c++ libstdc++

I'm trying to cross port a big autotools project to Android, but I'm having some issues with the NDK configuration (I guess). When I run the configure script, everything goes well until I reach a p...

bootstrap-wysihtml5-rails custom button

jquery html ruby-on-rails wysihtml5

In my project, we are using bootstrap-wysihtml editor for rich text editing.