UICollectionViewDelegate
The methods adopted by the object you use to manage user interactions with items in a collection view.
Declaration
@MainActor protocol UICollectionViewDelegate : UIScrollViewDelegateOverview
A collection view delegate manages user interactions with the collection view’s contents, including item selection, highlighting, and performing actions on those items. The methods of this protocol are all optional.
When configuring the collection view object, assign your delegate object to its delegate property. For more information, see UICollectionView.
Topics
Managing the selected cells
Changing the appearance of selected and highlighted cellsSelecting multiple items with a two-finger pan gesturecollectionView(_:shouldSelectItemAt:)collectionView(_:didSelectItemAt:)collectionView(_:shouldDeselectItemAt:)collectionView(_:didDeselectItemAt:)collectionView(_:shouldBeginMultipleSelectionInteractionAt:)collectionView(_:didBeginMultipleSelectionInteractionAt:)collectionViewDidEndMultipleSelectionInteraction(_:)
Managing cell highlighting
collectionView(_:shouldHighlightItemAt:)collectionView(_:didHighlightItemAt:)collectionView(_:didUnhighlightItemAt:)
Tracking the addition and removal of views
collectionView(_:willDisplay:forItemAt:)collectionView(_:willDisplaySupplementaryView:forElementKind:at:)collectionView(_:didEndDisplaying:forItemAt:)collectionView(_:didEndDisplayingSupplementaryView:forElementOfKind:at:)
Handling layout changes
collectionView(_:transitionLayoutForOldLayout:newLayout:)collectionView(_:targetContentOffsetForProposedContentOffset:)collectionView(_:targetIndexPathForMoveOfItemFromOriginalIndexPath:atCurrentIndexPath:toProposedIndexPath:)
Managing context menus
Adding context menus in your appcollectionView(_:willDisplayContextMenu:animator:)collectionView(_:willEndContextMenuInteraction:animator:)collectionView(_:willPerformPreviewActionForMenuWith:animator:)collectionView(_:contextMenuConfigurationForItemsAt:point:)collectionView(_:contextMenuConfiguration:highlightPreviewForItemAt:)collectionView(_:contextMenuConfiguration:dismissalPreviewForItemAt:)
Working with focus
collectionView(_:canFocusItemAt:)indexPathForPreferredFocusedView(in:)collectionView(_:shouldUpdateFocusIn:)collectionView(_:didUpdateFocusIn:with:)collectionView(_:selectionFollowsFocusForItemAt:)
Editing items
Managing actions for cells
Handling scene transitions
Controlling the spring-loading behavior
Deprecated
collectionView(_:targetIndexPathForMoveFromItemAt:toProposedIndexPath:)collectionView(_:contextMenuConfigurationForItemAt:point:)collectionView(_:previewForDismissingContextMenuWithConfiguration:)collectionView(_:previewForHighlightingContextMenuWithConfiguration:)collectionView(_:shouldShowMenuForItemAt:)collectionView(_:canPerformAction:forItemAt:withSender:)collectionView(_:performAction:forItemAt:withSender:)