iosswiftuitableviewheightforrowatindexpath

Keep some cell height unchanged, while changing others


I have a TableView of static cells (with different heights) and I am trying to hide a cell on load. I achieved it by using heightForRowAtIndexPath and returning 0 for the cell I want to close, but, for that function, I need to return a value..

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
   if indexPath.section == 2 && indexPath.row == 5 {
       return 0
   }

   // here:

   return tableView.rowHeight  // changes default values of cells
   return UITableViewAutomaticDimension // changes too.

    }

I want to return whatever height cell has.

I found this for obj-c and I feel like it would work, but I am not sure.. I couldn't translate it..

[super tableView:tableView heightForRowAtIndexPath:indexPath];

What is the way of keeping the cells' height as they have? Should I hardcode everything?


Solution

  • Just call the super implementation:

    return super.tableView(tableView, heightForRowAtIndexPath: indexPath)