Class

iAd.CellContainer

Cell Containers are subclasses of iAd.View that manage an ordered set of subviews referred to as cells. All cell containers provide a way for one of their cells to come into focus (i.e. become visually prominent) at a time. An example of a cell container is iAd.CarouselView.

Overview

iAd.CellContainer embodies both a protocol—the full set of methods and properties a class must implement in order to qualify as a cell container—and a mixin. The mixin is provided as a convenient way to implement cell container behaviors with very little code.

Classes that mix in iAd.CellContainer must do some additional work in order to fully function as cell containers:

  • Synthesize a focusedIndex property (the mixin provides getter and setter implementations).

  • Call init during the class's init() method.

  • Implement the focusCellAtIndexAnimated method. Because the whole point of cell containers is generally to provide a unique layout, the mixin cannot provide a generic implementation.

  • Optionally implement the updateLayout method. This method will be called when new cells are added and removed. This is where you can implement custom layout logic.

A very simple class that implements iAd.CellContainer might look like:

iAd.Class({
  name: 'CustomContainer',
  superclass: iAd.View,
  mixins: [iAd.CellContainer],
  synthesizedProperties: ['focusedIndex']
});

CustomContainer.prototype.init = function (layer) {
  iAd.CellContainer.init.call(this);
  this.callSuper(layer);
};

CustomContainer.prototype.focusCellAtIndexAnimated = function (index, animated) {
  // custom logic to animate to a new position
};

Symbols

Creating Cell Containers

iAd.CellContainer

Creates and returns a cell container.

init

Initializes various properties needed for the cell container mixin to function.

Setting Cell Container Properties

dataSource

The data source that provides the cells to the cell container.

delegate

The delegate that will be called when cells are in focus.

numberOfCells

The total number of cells the container is managing.

Managing Cell Index

focusedIndex

The index of the currently focused cell.

cellAtIndex

Returns the cell located at the given index in the cell container.

focusCellAtIndexAnimated

Focuses the cell at the given index.

insertCellsAtIndexes

Notifies the cell container that its data source has new cells to be displayed.

viewForCellAtIndex

Provides the view for the cell at the provided index.

removeCellsAtIndexes

Notifies the cell container that some cells have been removed from the data source.

Drawing Cells

dequeueReusableCell

Returns a reusable cell object.

reloadData

Notifies the view that there is new data to be drawn.