Instance Method


Selects the item at the specified index path and optionally scrolls it into view.


func selectItem(at indexPath: IndexPath?, animated: Bool, scrollPosition: UICollectionView.ScrollPosition)



The index path of the item to select. Specifying nil for this parameter clears the current selection.


Specify true to animate the change in the selection or false to make the change without animating it.


An option that specifies where the item should be positioned when scrolling finishes. For a list of possible values, see UICollectionView.ScrollPosition.


If the allowsSelection property is false, calling this method has no effect. If there is an existing selection with a different index path and the allowsMultipleSelection property is false, calling this method replaces the previous selection.

This method does not cause any selection-related delegate methods to be called.

See Also

Managing the Selection

var allowsSelection: Bool

A Boolean value that indicates whether users can select items in the collection view.

var allowsMultipleSelection: Bool

A Boolean value that determines whether users can select more than one item in the collection view.

var indexPathsForSelectedItems: [IndexPath]?

The index paths for the selected items.

func deselectItem(at: IndexPath, animated: Bool)

Deselects the item at the specified index.

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