1

I have to create a UIView Table in swift with 2 prototype cells, each having different heights. My first cell will only have a label and a button in same line, so its height should not be too much. Where as second cell will be having a image, 4 labels etc. so I need height for this. Is there a way I can change the height of dynamic tableview cell in code or IB?

Thanks!enter image description here

abhishek
  • 59
  • 6
  • possible duplicate of [Using Auto Layout in UITableView for dynamic cell layouts & variable row heights](http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights) – zrzka Jul 10 '15 at 13:07

3 Answers3

2

Set your controller as delegate for your UITableView. Then implement the optional function

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if indexPath.row == 0
      return 180
    else 
      return 40 }
Shamas S
  • 7,507
  • 10
  • 46
  • 58
1

could you use the function:

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    // return height for each cell
}

sorry if I've misunderstood the question.

Charlie Hall
  • 547
  • 4
  • 7
0

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

this is a method you can use to set the height of all your cell according to the indexpath that is a table view delegate method . set the height of cell it it programatically . if you want to set the height through Ui that you can set a static height for all the cell .