Cannot change the row height of TableViewCells - Swift

2.4k Views Asked by At

I am attempting to set the height of a custom tableViewCell, but the code below does not work. What is the better way to do this?

Programmatically:

override func viewDidLoad() {
  super.viewDidLoad()
  self.tableView.rowHeight = 140
}

via storyboard:

  1. Selected on tableView -> size Inspector -> set row height to 140.

I have also tried the following:

  1. Selected the custom UITableViewCell -> size Inspector -> set row height to 140.
1

There are 1 best solutions below

0
missionMan On BEST ANSWER

if you are using UITableViewController like this:

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 140.0
}

if you are using UIViewController, you must implement UITableViewDelegate

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 140.0
}