mercredi 25 mars 2015

swift how to set dynamic height when having multiple custom UITableViewCells

How do I set the height based on content, having multiple custom UITableViewCell ?


This is how I've tried:



func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
var currentCell:UITableViewCell? = tableView.cellForRowAtIndexPath(indexPath)
println("reuseIdentifier: \(currentCell?.reuseIdentifier)")

currentCell?.layoutIfNeeded()

let height: CGFloat = currentCell?.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height as CGFloat!
let separatorHeight:CGFloat = 1

return height + separatorHeight
}


but it crashes since I cannot get the current cell.




Aucun commentaire:

Enregistrer un commentaire