Protocol: UICollectionViewDelegate
Overview
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.Asks the delegate if it can perform the specified action on an item in the collection view.Tells the delegate that the item at the specified path was deselected.Tells the delegate that the specified cell was removed from the table. (required)Tells the delegate that the specified supplementary view was removed from the table. (required)Tells the delegate that the item at the specified index path was highlighted. Tells the delegate that the item at the specified index path was selected. Tells the delegate that the highlight was removed from the item at the specified index path.Tells the delegate to perform the specified action on an item in the collection view. Asks the delegate if the specified item should be deselected. Asks the delegate if the item should be highlighted during tracking. Asks the delegate if the specified item should be selected. Asks the delegate if an action menu should be displayed for the specified item.
Instance Method Summary (collapse)
-
- collectionView:canPerformAction:forItemAtIndexPath:withSender:
Asks the delegate if it can perform the specified action on an item in the collection view.
-
- collectionView:didDeselectItemAtIndexPath:
Tells the delegate that the item at the specified path was deselected.
-
- collectionView:didEndDisplayingCell:forItemAtIndexPath:
Tells the delegate that the specified cell was removed from the table.
-
- collectionView:didEndDisplayingSupplementaryView:forElementOfKind:atIndexPath:
Tells the delegate that the specified supplementary view was removed from the table.
-
- collectionView:didHighlightItemAtIndexPath:
Tells the delegate that the item at the specified index path was highlighted.
-
- collectionView:didSelectItemAtIndexPath:
Tells the delegate that the item at the specified index path was selected.
-
- collectionView:didUnhighlightItemAtIndexPath:
Tells the delegate that the highlight was removed from the item at the specified index path.
-
- collectionView:performAction:forItemAtIndexPath:withSender:
Tells the delegate to perform the specified action on an item in the collection view.
-
- collectionView:shouldDeselectItemAtIndexPath:
Asks the delegate if the specified item should be deselected.
-
- collectionView:shouldHighlightItemAtIndexPath:
Asks the delegate if the item should be highlighted during tracking.
-
- collectionView:shouldSelectItemAtIndexPath:
Asks the delegate if the specified item should be selected.
-
- collectionView:shouldShowMenuForItemAtIndexPath:
Asks the delegate if an action menu should be displayed for the specified item.
Instance Method Details
- (Boolean) collectionView(collectionView, canPerformAction:action, forItemAtIndexPath:indexPath, withSender:sender)
Asks the delegate if it can perform the specified action on an item in the collection view. This method is invoked after the collectionView:shouldShowMenuForItemAtIndexPath: method. It gives you the opportunity to exclude commands from the editing menu. For example, the user might have copied some content from one item and wants to paste it into another item that cannot accept the content. In such a case, your method could return NO to prevent the display of the relevant command.If you do not implement this method, the default return value is NO.
- (Object) collectionView(collectionView, didDeselectItemAtIndexPath:indexPath)
Tells the delegate that the item at the specified path was deselected. The collection view calls this method when the user successfully deselects an item in the collection view. It does not call this method when you programmatically deselect items.
- (Object) collectionView(collectionView, didEndDisplayingCell:cell, forItemAtIndexPath:indexPath)
Tells the delegate that the specified cell was removed from the table. (required) Use this method to detect when a cell is removed from a collection view, as opposed to monitoring the view itself to see when it appears or disappears.
- (Object) collectionView(collectionView, didEndDisplayingSupplementaryView:view, forElementOfKind:elementKind, atIndexPath:indexPath)
Tells the delegate that the specified supplementary view was removed from the table. (required) Use this method to detect when a supplementary view is removed from a collection view, as opposed to monitoring the view itself to see when it appears or disappears.
- (Object) collectionView(collectionView, didHighlightItemAtIndexPath:indexPath)
Tells the delegate that the item at the specified index path was highlighted. The collection view calls this method only in response to user interactions and does not call it if you programmatically set the highlighting on a cell.
- (Object) collectionView(collectionView, didSelectItemAtIndexPath:indexPath)
Tells the delegate that the item at the specified index path was selected. The collection view calls this method when the user successfully selects an item in the collection view. It does not call this method when you programmatically set the selection.
- (Object) collectionView(collectionView, didUnhighlightItemAtIndexPath:indexPath)
Tells the delegate that the highlight was removed from the item at the specified index path. The collection view calls this method only in response to user interactions and does not call it if you programmatically change the highlighting on a cell.
- (Object) collectionView(collectionView, performAction:action, forItemAtIndexPath:indexPath, withSender:sender)
Tells the delegate to perform the specified action on an item in the collection view. If the user taps an action in the editing menu, the collection view calls this method. Your implementation of this method should do whatever is appropriate for the action. For example, for a copy action, it should extract the relevant item content and write it to the general pasteboard or an application (private) pasteboard. For information about how to perform pasteboard-related operations, see UIPasteboard Class Reference.
- (Boolean) collectionView(collectionView, shouldDeselectItemAtIndexPath:indexPath)
Asks the delegate if the specified item should be deselected. The collection view calls this method when the user tries to deselect an item in the collection view. It does not call this method when you programmatically deselect items.If you do not implement this method, the default return value is YES.
- (Boolean) collectionView(collectionView, shouldHighlightItemAtIndexPath:indexPath)
Asks the delegate if the item should be highlighted during tracking. As touch events arrive, the collection view highlights items in anticipation of the user selecting them. As it processes those touch events, the collection view calls this method to ask your delegate if a given cell should be highlighted. It calls this method only in response to user interactions and does not call it if you programmatically set the highlighting on a cell.If you do not implement this method, the default return value is YES.
- (Boolean) collectionView(collectionView, shouldSelectItemAtIndexPath:indexPath)
Asks the delegate if the specified item should be selected. The collection view calls this method when the user tries to select an item in the collection view. It does not call this method when you programmatically set the selection.If you do not implement this method, the default return value is YES.
- (Boolean) collectionView(collectionView, shouldShowMenuForItemAtIndexPath:indexPath)
Asks the delegate if an action menu should be displayed for the specified item. If the user tap-holds a certain item in the collection view, this method (if implemented) is invoked first. Return YES if you want to permit the editing menu to be displayed. Return NO if the editing menu shouldn’t be shown—for example, you might return NO if the corresponding item contains data that should not be copied or pasted over.If you do not implement this method, the default return value is NO.