UICollectionReusableView Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 6.0 and later.
Declared in
UICollectionViewCell.h

Overview

The UICollectionReusableView class defines the behavior for all cells and supplementary views presented by a collection view. Reusable views are so named because the collection view places them on a reuse queue rather than deleting them when they are scrolled out of the visible bounds. Such a view can then be retrieved and repurposed for a different set of content.

Subclassing Notes

This class is intended to be subclassed. Most methods defined by this class have minimal or no implementations. You are not required to override any of the methods but can do so in cases where you want to respond to changes in the view’s usage or layout.

Tasks

Reusing Cells

Managing Layout Changes

Properties

reuseIdentifier

A string that identifies the purpose of the view. (read-only)

@property (nonatomic, readonly, copy) NSString *reuseIdentifier
Discussion

The collection view identifies and queues reusable views using their reuse identifiers. The collection view sets this value when it first creates the view, and the value cannot be changed later. When your data source is prompted to provide a given view, it can use the reuse identifier to dequeue a view of the appropriate type.

Availability
  • Available in iOS 6.0 and later.
Declared In
UICollectionViewCell.h

Instance Methods

applyLayoutAttributes:

Applies the specified layout attributes to the view.

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
Parameters
layoutAttributes

The layout attributes to apply.

Discussion

The default implementation of this method does nothing.

If the layout object supports custom layout attributes, you can use this method to apply those attributes to the view. In such a case, the layoutAttributes parameter should contain an instance of a subclass of UICollectionViewLayoutAttributes. You do not need to override this method to support the standard layout attributes of the UICollectionViewLayoutAttributes class. The collection view applies those attributes automatically.

Availability
  • Available in iOS 6.0 and later.
Declared In
UICollectionViewCell.h

didTransitionFromLayout:toLayout:

Tells your view that the layout object of the collection view changed.

- (void)didTransitionFromLayout:(UICollectionViewLayout *)oldLayout toLayout:(UICollectionViewLayout *)newLayout
Parameters
oldLayout

The collection view’s previous layout object.

newLayout

The current layout object associated with the collection view.

Discussion

The default implementation of this method does nothing. Subclasses can override this method and use it to finalize any behaviors associated with the change in layouts.

Availability
  • Available in iOS 6.0 and later.
Declared In
UICollectionViewCell.h

prepareForReuse

Performs any clean up necessary to prepare the view for use again.

- (void)prepareForReuse
Discussion

The default implementation of this method does nothing. However, when overriding this method, it is recommended that you call super anyway. Subclasses such as UICollectionViewCell override this method and use it to perform relevant actions. So if your subclass descends from UICollectionViewCell or some other intermediate class, calling super ensures that your class gets the parent’s behavior.

When a view is dequeued for use, this method is called before the corresponding dequeue method returns the view to your code. Subclasses can override this method and use it to reset properties to their default values and generally make the view ready to use again. You should not use this method to assign any new data to the view. That is the responsibility of your data source object.

Availability
  • Available in iOS 6.0 and later.
Declared In
UICollectionViewCell.h

willTransitionFromLayout:toLayout:

Tells your view that the layout object of the collection view is about to change.

- (void)willTransitionFromLayout:(UICollectionViewLayout *)oldLayout toLayout:(UICollectionViewLayout *)newLayout
Parameters
oldLayout

The current layout object associated with the collection view.

newLayout

The new layout object that is about to be applied to the collection view.

Discussion

The default implementation of this method does nothing. Subclasses can override this method and use it to prepare for the change in layouts.

Availability
  • Available in iOS 6.0 and later.
Declared In
UICollectionViewCell.h