NEVERCODE Develop apps 20% faster with the leading CI/CD partner for iOS, Android, Cordova, Ionic, React Native & Flutter projects Try It

Today we'll check out a few different tips and tricks for working with UITableView. Let's get started.

Adding a Refresh Control

We can add pull-to-refresh capabilities to any UITableView easily:

let refreshControl = UIRefreshControl()
  action: Selector("refreshed:"), 
  forControlEvents: .ValueChanged


Then we just implement that refreshed: function like this:

func refreshed(sender: UIRefreshControl) {
  refreshTheThing {

Reload Visible Cells

Here's a quick (almost) one-liner to reload only the visible cells in the table view:

  tableView.indexPathsForVisibleRows ?? [],
  withRowAnimation: .Automatic

Accessing Rects

It's often handy to grab a reference to the actual frame of a cell, section, header or footer. We can do this easily with:


Animate Height Changes

One easy trick to make our app look a little nicer is to animate changes to the heights of the UITableViewCells in our UITableView. All we need to do is make whatever changes to our models we want to cause our cells to be a different height. (For example we might let the user tap a button to "expand" all comments in an app). Then we just call:


UIKit will interpolate & animate the changes, neat!