2
votes

I have an UIViewController embedded into an UINavigationController. My UIViewController contain an UITableView that have two types of cells: cell1 (the first cell) have height = 250, and cell2 have height = 85. Everything works fine in the beginning but when I tape a cell to show its detail using self.navigationController?.pushViewController(vc, animated: true) , then when I return to the parentViewController (the one containing the UITableView) the cell1 got the height of cell2. In the storyboard I have set the rowHeight of the table as 250, for the view of the cell1 250 and for the cell2 one I have 85. Then in the controller I set the table.rowHeight in function of the index.row as you can see in the code above:

// MARK: - Table view

    private func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }


    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataSource.count
    }


    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 if indexPath.row == 0 {
            tableView.rowHeight = 260
            var cell = tableView.dequeueReusableCell(withIdentifier: "homeFirstTableViewCell") as? HomeFirstTableViewCell
//set the content of the cell
} else {
            tableView.rowHeight = 85
            var cell = tableView.dequeueReusableCell(withIdentifier: "homeTableViewCell") as? HomeTableViewCell
}
}

Note:

I have this problem only with the iOS 8 devices

Edit:

When I tried this:

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

        if(indexPath.row == 0 ){
            return 260
        }

        return 85
    }

The first cell having cell2 as type got the height of cell1

1
you should implement func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat to set the row heightJeremy

1 Answers

0
votes

You need to set the constraints of the content of your cells in the storyboard or xib (if you created them in one), one way to doing this is creating a containerView and assigning it a height constraint, and use this method

tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat

instead of this

tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat

And return an abstract number between 85 and 250