Dynamic Height Issue for UITableView Cells (Swift)
Try This:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension}
EDIT
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension}
Swift 4
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { return UITableViewAutomaticDimension}
Swift 4.2
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { return UITableView.automaticDimension}
Define above Both Methods.
It solves the problem.
PS: Top and bottom constraints is required for this to work.
Use this:
tableView.rowHeight = UITableViewAutomaticDimensiontableView.estimatedRowHeight = 300
and don't use: heightForRowAtIndexPath
delegate function
Also, in the storyboard don't set the height of the label that contains a large amount of data. Give it top, bottom, leading, trailing
constraints.
SWIFT 3
tableView.rowHeight = UITableViewAutomaticDimensiontableView.estimatedRowHeight = 160
AND!!!In storyBoard: You HAVE TO set TOP & BOTTOM constraints for your Label.Nothing else.