DevPrep

All topics › UIKit

How do you animate a table cell's height change?

Middle PRO

The gist

The table, not the cell, decides the cell's height, so you need to (1) change the data or the constraints inside contentView and (2) ask the table to recompute heights inside an animatable block: performBatchUpdates(nil) (or the older beginUpdates() / endUpdates() pair). The table re-queries the heights of visible cells and animates the change.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store