CollectionViewDelegate

@objc
public protocol CollectionViewDelegate

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

  • Notifies the delegate that the collection view will reload it’s layout

    It can be assumed that the data has been reloaded

    Note

    Calculating layout properties that can be cached can be done here and later returned in associated the layout delegate methods.

    Declaration

    Swift

    @objc
    optional func collectionViewWillReloadLayout(_ collectionView: CollectionView)

    Parameters

    collectionView

    The collection view is reloading it’s layout

  • Notifies the delegate that the collection view finished reloading it’s layout

    It can be assumed that the data has been reloaded and is up to date

    Declaration

    Swift

    @objc
    optional func collectionViewDidReloadLayout(_ collectionView: CollectionView)

    Parameters

    collectionView

    The collection view

  • Notifies the delegate that the collection view has changed status as first responder

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, didChangeFirstResponderStatus firstResponder: Bool)

    Parameters

    collectionView

    The collection view changing status

    firstResponder

    True if the collection view is first responder

  • Notifies the delegate that the mouse has moved into the frame of a section.

    Note

    trackSectionHover must be set to true on the collection view

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, mouseMovedToSection indexPath: IndexPath?)

    Parameters

    collectionView

    The collection view notifying you of the event

    indexPath

    the index path of the section

  • Notifies the delegate that the mouse was clicked down in the specified index path

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, mouseDownInItemAt indexPath: IndexPath?, with event: NSEvent)

    Parameters

    collectionView

    The collection view recieving the click

    indexPath

    The index path of the item at the click location, or nil

    event

    The click event

  • Notifies the delegate that the mouse was released in the specified index path

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, mouseUpInItemAt indexPath: IndexPath?, with event: NSEvent)

    Parameters

    collectionView

    The collection view receiving the click

    indexPath

    The index path of the item at the click location, or nil

    event

    The click even

  • Asks the delegate if the item at the specified index path should highlight

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool

    Parameters

    collectionView

    The asking collection view

    indexPath

    The index path of the item to highlight

    Return Value

    True if the item should highlight

  • Asks the delegate to approve the pending selection of items.

    Use this method to approve or modify the items that the user tries to select. During interactive selection, the collection view calls this method whenever the user selects new items. Your implementation of the method can return the proposed set of index paths as-is or modify the set before returning it. You might modify the set to disallow the selection of specific items or specific combinations of items.

    If you do not implement this method, the collection view selects the items specified by the indexPaths parameter.

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, shouldSelectItemsAt indexPaths: Set<IndexPath>) -> Set<IndexPath>

    Parameters

    collectionView

    The collection view making the request.

    indexPath

    The set of NSIndexPath objects corresponding to the items selected by the user.

    event

    The event that cause the selection

    Return Value

    The set of NSIndexPath objects corresponding to the items that you want to be selected. If you do not want any items selected, return an empty set.

  • Notifies the delegate object that one or more items were selected.

    After the user successfully selects one or more items, the collection view calls this method to let you know that the selection has been made. Use this method to respond to the selection change and to make any necessary adjustments to your content or the collection view.

    Note

    The provided index paths do not inlcude index paths selected prior to this event.

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, didSelectItemsAt indexPaths: Set<IndexPath>)

    Parameters

    collectionView

    The collection view notifying you of the selection change.

    indexPath

    The set of NSIndexPath objects corresponding to the items that are now selected.

  • Asks the delegate object to approve the pending deselection of items.

    Use this method to approve or modify the items that the user tries to deselect. During interactive selection, the collection view calls this method whenever the user deselects items. Your implementation of the method can return the proposed set of index paths as-is or modify the set before returning it. You might modify the set to disallow the deselection of specific items.

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, shouldDeselectItemsAt indexPaths: Set<IndexPath>) -> Set<IndexPath>

    Parameters

    collectionView

    The collection view making the request.

    indexPath

    The set of NSIndexPath objects corresponding to the items deselected by the user.

    Return Value

    The set of NSIndexPath objects corresponding to the items that you want to be selected. If you do not want any items selected return an empty set.

  • Notifies the delegate object that one or more items were deselected.

    After the user successfully deselects one or more items, the collection view calls this method to let you know that the items are no longer selected. Use this method to respond to the selection change and to make any necessary adjustments to your content or the collection view.

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, didDeselectItemsAt indexPaths: Set<IndexPath>)

    Parameters

    collectionView

    The collection view notifying you of the selection change.

    indexPath

    The set of NSIndexPath objects corresponding to the items that were deselected.

  • Notifies the delegate that an item was double clicked

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, didDoubleClickItemAt indexPath: IndexPath?, with event: NSEvent)

    Parameters

    collectionView

    The collection view containing the clicked item

    indexPath

    The index path of the clicked item

    event

    The click event that double clicked the item

  • Notifies the delegate that an item was right clicked

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, didRightClickItemAt indexPath: IndexPath?, with event: NSEvent)

    Parameters

    collectionView

    The collection view containing the clicked item

    indexPath

    The index path of the clicked item

    event

    The click event

  • Notifies the delegate that a supplementary view will bw displayed

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, willDisplaySupplementaryView view: CollectionReusableView, ofElementKind elementKind: String, at indexPath: IndexPath)

    Parameters

    collectionView

    The collection view containing the supplementary view

    elementKind

    The element kind of the view

    indexPath

    The index path of the view

  • Notifies the delegate that a cell was removed from view

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, didEndDisplayingCell cell: CollectionViewCell, forItemAt indexPath: IndexPath)

    Parameters

    collectionView

    The collection view containing the cell

    cell

    The cell that was removed

    indexPath

    The index path of the removed cell

  • Notifies the delegate that a supplementary view was removed from view

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, didEndDisplayingSupplementaryView view: CollectionReusableView, ofElementKind elementKind: String, at indexPath: IndexPath)

    Parameters

    collectionView

    The collection view containing the supplementary view

    view

    The view that was removed

    elementKind

    The kind of the removed element

    indexPath

    The index path of the removed view

  • Asks the delegate for an index path to anchor when resizing

    Defaults to an index path for one of the first visible items

    Declaration

    Swift

    @objc
    optional func collectionViewLayoutAnchor(_ collectionView: CollectionView) -> IndexPath?

    Parameters

    collectionView

    The collection view

    Return Value

    The index path to anchor to when resizing

  • Notifies the delegate that the collection view did begin resizing

    Declaration

    Swift

    @objc
    optional func collectionViewDidEndLiveResize(_ collectionView: CollectionView)

    Parameters

    collectionView

    The collection view

  • Asks the delegate if the collection view should scroll to an item

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, shouldScrollToItemAt indexPath: IndexPath) -> Bool

    Parameters

    collectionView

    The collection view

    indexPath

    The index path that may be scrolled to

    Return Value

    True if the collection view should perform the scroll

  • Notifies the delegate that the collection view did complete a scrolling action

    Declaration

    Swift

    @objc
    optional func collectionView(_ collectionView: CollectionView, didScrollToItemAt indexPath: IndexPath)

    Parameters

    collectionView

    The collection view that performed a scrolling animation

    indexPath

    The index path that was scrolled to

  • Notifies the delegate that the collection view was scrolled

    Because this is called continuously as the scroll position is changed, beware of performance.

    Declaration

    Swift

    @objc
    optional func collectionViewDidScroll(_ collectionView: CollectionView)

    Parameters

    collectionView

    The collection view that was scrolled

  • Notifies the delegate that the collection view will begin scrolling

    Declaration

    Swift

    @objc
    optional func collectionViewWillBeginScrolling(_ collectionView: CollectionView, animated: Bool)

    Parameters

    collectionView

    The collection view that will begin scrolling

    aniated

    If the scroll is triggered by user input, this will be false

  • Notifies the delegate that the collection view did end scrolling

    Declaration

    Swift

    @objc
    optional func collectionViewDidEndScrolling(_ collectionView: CollectionView, animated: Bool)

    Parameters

    collectionView

    The collection view that was scrolled

    animated

    True if the scroll was animated (false for user driven scrolling)