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 |
Overview
The UICollectionViewController class represents a view controller whose content consists of a collection view. It implements the following behavior:
If the collection view controller has an assigned nib file or was loaded from a storyboard, it loads its view from the corresponding nib file or storyboard. If you create the collection view controller programmatically, it automatically creates a new unconfigured collection view object, which you can access using the
collectionViewproperty.When loading a collection view from a storyboard or nib file, the data source and delegate objects for the collection view are obtained from the nib file. If a data source or delegate is not specified, the collection view controller assigns itself to the unspecified role.
When the collection view is about to appear for the first time, the collection view controller reloads the collection view data. It also clears the current selection every time the view is displayed. You can change this behavior by setting the value of the
clearsSelectionOnViewWillAppearproperty toNO.
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
-
collectionViewproperty
Configuring the Collection View Behavior
-
clearsSelectionOnViewWillAppearproperty
Properties
clearsSelectionOnViewWillAppear
A Boolean value indicating if the controller clears the selection when the collection view appears.
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.hcollectionView
The collection view object managed by this view controller.
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.
Declared In
UICollectionViewController.hInstance Methods
initWithCollectionViewLayout:
Initializes a collection view controller and configures the collection view with the provided 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© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-09-19)