How to change the height of a prototype cell in Xcode for tableView?

Viewed 9795

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

4 Answers

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
}

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)
    }

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
Related