Contents

selectItem(at:animated:scrollPosition:)

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

Declaration

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

Parameters

  • indexPath:

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

  • animated:

    Specify True to animate the change in the selection or False to make the change without animating it.

  • scrollPosition:

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

Discussion

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

This method doesn’t cause any selection-related delegate methods to be called.

See Also

Selecting cells