O'Reilly logo

iOS 8 SDK Development, 2nd Edition by Janie Clayton, Chris Adamson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Cell Reuse

Right now, we create a new UITableViewCell in every call to tableView(cellForRowAtIndexPath:). If we flick through a really long table, that might mean we create a cell that will only appear for an instant before it goes off the screen and is no longer needed. As it turns out, creating views is fairly expensive, so if we can avoid doing that frequently, it will make our app faster and more responsive.

The UITableView class is actually built to cache and reuse cells. It provides a method, dequeueReusableCellWithIdentifier, that takes a string identifying a cell to be reused. The idea is that we can create a cell in the storyboard as a sort of template and identify it with a known string. In code, we’ll ask for a cell by this name. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required