UICollectionViewController Class Reference

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

Overview

The UICollectionViewController class represents a view controller whose content consists of a collection view. It implements the following behavior:

You create a custom subclass of UICollectionViewController for each collection view that you want to manage. When you initialize the controller, using the initWithCollectionViewLayout: method, you specify the layout the collection view should have. Because the initially created collection view is without dimensions or content, the collection view’s data source and delegate—typically the collection view controller itself—must provide this information.

You may override the loadView method or any other superclass method, but if you do, be sure to call super in the implementation of your method. If you do not, the collection view controller may not be able to perform all of the tasks needed to maintain the integrity of the collection view.

Tasks

Initializing the UICollectionViewController Object

Getting the Collection View

Configuring the Collection View Behavior

Integrating with a Navigation Controller

Properties

clearsSelectionOnViewWillAppear

A Boolean value indicating if the controller clears the selection when the collection view appears.

@property (nonatomic) BOOL clearsSelectionOnViewWillAppear
Discussion

The default value of this property is YES. When YES, the collection view controller clears the collection view’s current selection when it receives a viewWillAppear: message. Setting this property to NO preserves the selection.

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

collectionView

The collection view object managed by this view controller.

@property (nonatomic, retain) UICollectionView *collectionView
Discussion

If you assign a new collection view object to this property and that view’s data source or delegate are not yet set, the collection view controller makes itself the delegate or data source or both.

Availability
  • Available in iOS 6.0 and later.
Related Sample Code
Declared In
UICollectionViewController.h

collectionViewLayout

The layout object used to initialize the collection view controller. (read-only)

@property (nonatomic,readonly) UICollectionViewLayout *collectionViewLayout
Discussion

This property contains the layout object you passed to the initWithCollectionViewLayout: method. The layout object in this property is not updated to reflect changes to the collection view itself. You can use this property to refer to the layout object you originally configured the collection view to use.

Availability
  • Available in iOS 7.0 and later.
Declared In
UICollectionViewController.h

useLayoutToLayoutNavigationTransitions

A Boolean that indicates whether the collection view controller coordinates with a navigation controller for transitions.

@property (nonatomic,assign) BOOL useLayoutToLayoutNavigationTransitions
Discussion

This property helps facilitate transitions between two or more collection view controllers using a navigation controller. When configuring your navigation controller, install a collection view controller as the root object on the navigation stack and set its value for this property to NO. When the user selects an item that would require pushing a new collection view controller on the stack, set the value of this property for the new view controller to YES. When you do that, the navigation controller performs an animated layout change between the contents of the two collection view controllers instead of the traditional push animation. Similarly, popping the topmost collection view controller off the stack animates back to the previous layout. The navigation controller drives the transition between the view controllers, including the ability to drive the transition interactively.

You must set the value of this property before pushing the collection view controller onto a navigation stack. Do not change the value of this property after the view controller is already on the navigation stack.

Availability
  • Available in iOS 7.0 and later.
Declared In
UICollectionViewController.h

Instance Methods

initWithCollectionViewLayout:

Initializes a collection view controller and configures the collection view with the provided layout.

- (id)initWithCollectionViewLayout:(UICollectionViewLayout *)layout
Parameters
layout

The layout object to associate with the collection view. The layout controls how the collection view presents its cells and supplementary views.

Return Value

An initialized UICollectionViewController object or nil if the object could not be created.

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