Kex
Kex

Reputation: 8629

Setting cell height for only one cell type and retaining dynamic heights for others

I have a UITableView with dynamic heights for cells. However there is a particular cell type I want to assign a fixed height to. My code is as follows:

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

        if indexPath.section == 1 && indexPath.row == 0 {
            guard let answerType = question.answerType else {
                return //What value here?
            }
            if answerType == .Text {
                return tableView.frame.height
            }
        }
    }

However I'm not sure what value to return in the guard statement. I don't want my other cells to be fixed height but instead remain dynamic. How can I go about doing this? Any pointers would be really appreciated! thanks

Upvotes: 2

Views: 424

Answers (1)

Vishal Sonawane
Vishal Sonawane

Reputation: 2693

You can return UITableViewAutomaticDimension from the guard statement. It will return dynamic height for cell.

Upvotes: 7

Related Questions