5.0. Introduction
Table views are great. They really are. However, they are very rigid in that they always render their content vertically. They aren’t grids and weren’t meant to act like grids. However, as a programmer, you may find yourself in a situation where you want to draw a grid-like component with columns and rows, and put different types of UI objects in each one, or make each one interactive. In a table view, you essentially have one column containing multiple rows. If you want to create an illusion of multiple columns, you will have to provide a custom cell and make that cell look like it is constructed out of multiple columns.
Collection views, just like table views, are based on the concept of cells, with each cell containing an item or view that it renders on the screen. Cells in collection views are reusable, just like in table views, and they can be dequeued and brought back to the screen whenever possible and needed. But the layout can be almost anything you can think of that works in two dimensions.
For this reason, Apple introduced collection views in version 6 of the iOS SDK. A collection view is simply a scroll view on steroids. It has a data source and a delegate, just like a table view, but it has one property that sets it apart from table views or scroll views: the layout object.
What the layout object does is essentially calculate where each item in the collection view has to be placed. Apple has made this a bit complicated, though, by introducing a concrete ...
Get iOS 7 Programming Cookbook 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.