Chapter    8

Creating Custom Cells with Subclasses

In Chapter 7, you looked at two of the three main ways of creating and configuring custom table view and collection view cells:

  • Adding subviews to the cell’s built-in contentView
  • Creating a custom cell from scratch and instantiating it from a XIB file

The third approach, which provides the greatest flexibility, albeit at the cost of slightly more complexity, is to create a custom subclass of UITableViewCell or UICollectionViewCell.

The main reasons for using this approach are that you need multiple types of cells in the same table or collection view, or in the case of table views, you want a level of control over the contents that is awkward to achieve by adding subviews.

In this chapter, you ...

Get Pro iOS Table Views and Collection Views: Using Swift 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.