Protocol

UICollectionViewDelegate

The UICollectionViewDelegate protocol defines methods that allow you to manage the selection and highlighting of items in a collection view and to perform actions on those items. The methods of this protocol are all optional.

Declaration

@protocol UICollectionViewDelegate

Overview

Many methods of this protocol take NSIndexPath objects as parameters. To support collection views, UIKit declares a category on NSIndexPath that enables you to get the represented item index and section index, and to construct new index path objects from item and index values. Because items are located within their sections, you usually must evaluate the section index number before you can identify the item by its index number.

When configuring the collection view object, assign your delegate object to its delegate property. For more information, see UICollectionView.

Topics

Managing the Selected Cells

- collectionView:shouldSelectItemAtIndexPath:

Asks the delegate if the specified item should be selected.

- collectionView:didSelectItemAtIndexPath:

Tells the delegate that the item at the specified index path was selected.

- collectionView:shouldDeselectItemAtIndexPath:

Asks the delegate if the specified item should be deselected.

- collectionView:didDeselectItemAtIndexPath:

Tells the delegate that the item at the specified path was deselected.

Managing Cell Highlighting

- collectionView:shouldHighlightItemAtIndexPath:

Asks the delegate if the item should be highlighted during tracking.

- collectionView:didHighlightItemAtIndexPath:

Tells the delegate that the item at the specified index path was highlighted.

- collectionView:didUnhighlightItemAtIndexPath:

Tells the delegate that the highlight was removed from the item at the specified index path.

Tracking the Addition and Removal of Views

- collectionView:willDisplayCell:forItemAtIndexPath:

Tells the delegate that the specified cell is about to be displayed in the collection view.

- collectionView:willDisplaySupplementaryView:forElementKind:atIndexPath:

Tells the delegate that the specified supplementary view is about to be displayed in the collection view.

- collectionView:didEndDisplayingCell:forItemAtIndexPath:

Tells the delegate that the specified cell was removed from the collection view.

- collectionView:didEndDisplayingSupplementaryView:forElementOfKind:atIndexPath:

Tells the delegate that the specified supplementary view was removed from the collection view.

Handling Layout Changes

- collectionView:transitionLayoutForOldLayout:newLayout:

Asks for the custom transition layout to use when moving between the specified layouts.

- collectionView:targetContentOffsetForProposedContentOffset:

Gives the delegate an opportunity to customize the content offset for layout changes and animated updates.

- collectionView:targetIndexPathForMoveFromItemAtIndexPath:toProposedIndexPath:

Asks the delegate for the index path to use when moving an item.

Managing Actions for Cells

- collectionView:shouldShowMenuForItemAtIndexPath:

Asks the delegate if an action menu should be displayed for the specified item.

Deprecated
- collectionView:canPerformAction:forItemAtIndexPath:withSender:

Asks the delegate if it can perform the specified action on an item in the collection view.

Deprecated
- collectionView:performAction:forItemAtIndexPath:withSender:

Tells the delegate to perform the specified action on an item in the collection view.

Deprecated

Managing Focus in a Collection View

- collectionView:canFocusItemAtIndexPath:

Asks the delegate whether the item at the specified index path can be focused.

- indexPathForPreferredFocusedViewInCollectionView:

Asks the delegate for the index path of the cell that should be focused.

- collectionView:shouldUpdateFocusInContext:

Asks the delegate whether a change in focus should occur.

- collectionView:didUpdateFocusInContext:withAnimationCoordinator:

Tells the delegate that a focus update occurred.

Controlling the Spring-Loading Behavior

- collectionView:shouldSpringLoadItemAtIndexPath:withContext:

Returns a Boolean value indicating whether you want the spring-loading interaction effect displayed for the specified item.

See Also

Managing Collection View Interactions

delegate

The object that acts as the delegate of the collection view.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software