2

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.
Troy Alford
  • 26,660
  • 10
  • 64
  • 82
johnDoe
  • 709
  • 11
  • 29
  • Take a look here - https://stackoverflow.com/q/31155795/2908082 – Eridana Nov 16 '17 at 13:25
  • You don't need to implement delegate method if you have same height for all the rows. You can do this through storyboard https://stackoverflow.com/a/46519806/4272498 – Irfan Nov 16 '17 at 15:09

1 Answers1

4

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
}
missionMan
  • 873
  • 8
  • 21