Resizing table view cells dynamically
In the previous demos, we saw that all the cells have the static cell height that can be configured from the storyboard. In this section, we will learn to resize table view cells dynamically, that is, based on the content height you have in your cell. Use this feature only if you want your cell to be resized based on the content height. Autolayout will help us greatly in this section and I recommend revising/reading the Autolayout chapter before starting this section.
How to do it...
Create a new Xcode project with the name
Dynamic Cells
and a Single View template.Add a
UITableView
with the delegate and data source set. Add a prototype cell with a basic style, as we did in section one. Implement the delegate and data source and display only four cells.In
ViewController.swift
, add the following titles to be displayed:let titles = ["This is very simple title", "Long text goes here\nLong text goes here\nLong text goes here\nLong...