Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table View Cell Row Height doesnt work

enter image description here

I have tried to hard code the row height in the table view cell. After running the program it looks like only one line. I suspect it is because of the height of the row of the table view.

Could you please tell me what went wrong in here?

like image 637
Agung Laksana Avatar asked Oct 02 '17 04:10

Agung Laksana


People also ask

How do you make a table dynamic cell height?

To get dynamic cell heights working properly, you need to create a custom table view cell and set it up with the right Auto Layout constraints. In the project navigator, select the Views group and press Command-N to create a new file in this group.

How do I change cell height in Swift?

To change the height of tableView cell in ios dynamically, i.e resizing the cell according to the content available, we'll need to make use of automatic dimension property. We'll see this with the help of an sample project.


2 Answers

Add this code in your UITableViewDelegate

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {     return 100 } 
like image 34
Leo Avatar answered Sep 18 '22 08:09

Leo


In Xcode 9, tableview automatically create estimated cells based on Autolayout. Since you have not provide autolayout, that's why you are getting this.

You need to disable estimated and automatic cell size by selecting tableview and uncheck the two options:

enter image description here

Give value you want to Row height, and cell will be created accordingly.

Hope this can help.

like image 186
Irfan Avatar answered Sep 19 '22 08:09

Irfan