9

I have dragged a UITableView into my storyboard and I can fully insert info into it. But in order to customise the cell I added a prototype cell. When I change the height of it manually nothing changes in the simulator.

enter image description here

Suragch
  • 364,799
  • 232
  • 1,155
  • 1,198
Danial Kosarifa
  • 944
  • 1
  • 15
  • 34

4 Answers4

15

For those who come here just wanting to change the row height during design time, you can select the Table View Cell and then set the row height in the Size inspector.

enter image description here

I'm adding this answer because I found this question when I was having trouble manually dragging the cell height to something else. As the OP noted, though, this will not change the cell height at run time. The cell is auto-sized depending on its content. If you need to give it a fixed height, see the accepted answer.

Suragch
  • 364,799
  • 232
  • 1,155
  • 1,198
11

You can change the height of a cell by adding Constraints to your label inside the cell or otherwise by adding this to your viewDidLoad:

tableView.rowHeight = 40

Or you may add the following delegate function to change the height:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 40
}
Murad Ali
  • 444
  • 3
  • 16
  • Is there really no way to do this in the storyboard? – Jonas Jun 29 '18 at 19:47
  • @Jonas you can do in storyboard by clicking on the cell and then change the row height value under size inspector. – Murad Ali Jun 30 '18 at 00:30
  • 4
    I tried that but that shows up only in the storyboard itself but when testing in the emulator it didn't change it – Jonas Jun 30 '18 at 08:06
  • 2
    @Jonas -> You need to click on the table view in the Storyboard, then click on the "Size inspector" on your right toolbar (looks like a measuring ruler) and you will see under "Table View" a property called "Row Height", make sure "Automatic" isn't checked and change it there. Try that and see if it works. [XCode Version 11.3.1] – TSuperman Mar 20 '20 at 19:29
2

You can use tableView delegate method and specify the value for your heightForRowAt

say you want it to be 80:

 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return CGFloat(80)
    }
bona912
  • 369
  • 1
  • 5
  • 11
0

The accepted answer wasn't working for me. What did work for me was adding the tableview rowheight under the following delegate:

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{

        tableView.rowHeight = 350
Will Buffington
  • 407
  • 4
  • 9