ASCollectionNode Class Reference
Inherits from | ASDisplayNode : ASDealloc2MainObject |
---|---|
Conforms to | ASRangeControllerUpdateRangeProtocol |
Declared in | ASCollectionNode.h |
Overview
ASCollectionNode is a node based class that wraps an ASCollectionView. It can be used as a subnode of another node, and provide room for many (great) features and improvements later on.
– initWithCollectionViewLayout:
Initializes an ASCollectionNode
- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout
Parameters
layout |
The layout object to use for organizing items. The collection view stores a strong reference to the specified object. Must not be nil. |
---|
Discussion
Initializes and returns a newly allocated collection node object with the specified layout.
Declared In
ASCollectionNode.h
– initWithFrame:collectionViewLayout:
Initializes an ASCollectionNode
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
Parameters
frame |
The frame rectangle for the collection view, measured in points. The origin of the frame is relative to the superview in which you plan to add it. This frame is passed to the superclass during initialization. |
---|---|
layout |
The layout object to use for organizing items. The collection view stores a strong reference to the specified object. Must not be nil. |
Discussion
Initializes and returns a newly allocated collection node object with the specified frame and layout.
Declared In
ASCollectionNode.h
view
Returns the corresponding ASCollectionView
@property (strong, nonatomic, readonly) ASCollectionView *view
Return Value
view The corresponding ASCollectionView.
Declared In
ASCollectionNode.h
delegate
The object that acts as the asynchronous delegate of the collection view
@property (weak, nonatomic) id<ASCollectionDelegate> delegate
Discussion
The delegate must adopt the ASCollectionDelegate protocol. The collection view maintains a weak reference to the delegate object.
The delegate object is responsible for providing size constraints for nodes and indicating whether batch fetching should begin.
Note: This is a convenience method which sets the asyncDelegate on the collection node’s collection view.
Declared In
ASCollectionNode.h
dataSource
The object that acts as the asynchronous data source of the collection view
@property (weak, nonatomic) id<ASCollectionDataSource> dataSource
Discussion
The datasource must adopt the ASCollectionDataSource protocol. The collection view maintains a weak reference to the datasource object.
The datasource object is responsible for providing nodes or node creation blocks to the collection view.
Note: This is a convenience method which sets the asyncDatasource on the collection node’s collection view.
Declared In
ASCollectionNode.h
allowsSelection
A Boolean value that indicates whether users can select items in the collection node. If the value of this property is YES (the default), users can select items. If you want more fine-grained control over the selection of items, you must provide a delegate object and implement the appropriate methods of the UICollectionNodeDelegate protocol.
@property (nonatomic, assign) BOOL allowsSelection
Declared In
ASCollectionNode.h
allowsMultipleSelection
A Boolean value that determines whether users can select more than one item in the collection node. This property controls whether multiple items can be selected simultaneously. The default value of this property is NO. When the value of this property is YES, tapping a cell adds it to the current selection (assuming the delegate permits the cell to be selected). Tapping the cell again removes it from the selection.
@property (nonatomic, assign) BOOL allowsMultipleSelection
Declared In
ASCollectionNode.h
– tuningParametersForRangeType:
Tuning parameters for a range type in full mode.
- (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType
Parameters
rangeType |
The range type to get the tuning parameters for. |
---|
Return Value
A tuning parameter value for the given range type in full mode.
Declared In
ASCollectionNode.h
– setTuningParameters:forRangeType:
Set the tuning parameters for a range type in full mode.
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
Parameters
tuningParameters |
The tuning parameters to store for a range type. |
---|---|
rangeType |
The range type to set the tuning parameters for. |
Declared In
ASCollectionNode.h
– tuningParametersForRangeMode:rangeType:
Tuning parameters for a range type in the specified mode.
- (ASRangeTuningParameters)tuningParametersForRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType
Parameters
rangeMode |
The range mode to get the running parameters for. |
---|---|
rangeType |
The range type to get the tuning parameters for. |
Return Value
A tuning parameter value for the given range type in the given mode.
Declared In
ASCollectionNode.h
– setTuningParameters:forRangeMode:rangeType:
Set the tuning parameters for a range type in the specified mode.
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType
Parameters
tuningParameters |
The tuning parameters to store for a range type. |
---|---|
rangeMode |
The range mode to set the running parameters for. |
rangeType |
The range type to set the tuning parameters for. |
Declared In
ASCollectionNode.h
– scrollToItemAtIndexPath:atScrollPosition:animated:
Scrolls the collection to the given item.
- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated
Parameters
indexPath |
The index path of the item. |
---|---|
scrollPosition |
Where the item should end up after the scroll. |
animated |
Whether the scroll should be animated or not. This method must be called on the main thread. |
Declared In
ASCollectionNode.h
– registerSupplementaryNodeOfKind:
Registers the given kind of supplementary node for use in creating node-backed supplementary elements.
- (void)registerSupplementaryNodeOfKind:(NSString *)elementKind
Parameters
elementKind |
The kind of supplementary node that will be requested through the data source. |
---|
Discussion
Use this method to register support for the use of supplementary nodes in place of the default
registerClass:forSupplementaryViewOfKind:withReuseIdentifier:
and registerNib:forSupplementaryViewOfKind:withReuseIdentifier:
methods. This method will register an internal backing view that will host the contents of the supplementary nodes
returned from the data source.
Declared In
ASCollectionNode.h
– performBatchAnimated:updates:completion:
Perform a batch of updates asynchronously, optionally disabling all animations in the batch. This method must be called from the main thread. The data source must be updated to reflect the changes before the update block completes.
- (void)performBatchAnimated:(BOOL)animated updates:(nullable __attribute ( ( noescape ) ) void ( ^ ) ( ))updates completion:(nullable void ( ^ ) ( BOOL finished ))completion
Parameters
animated |
NO to disable animations for this batch |
---|---|
updates |
The block that performs the relevant insert, delete, reload, or move operations. |
completion |
A completion handler block to execute when all of the operations are finished. This block takes a single Boolean parameter that contains the value YES if all of the related animations completed successfully or NO if they were interrupted. This parameter may be nil. If supplied, the block is run on the main thread. |
Declared In
ASCollectionNode.h
– performBatchUpdates:completion:
Perform a batch of updates asynchronously, optionally disabling all animations in the batch. This method must be called from the main thread. The data source must be updated to reflect the changes before the update block completes.
- (void)performBatchUpdates:(nullable __attribute ( ( noescape ) ) void ( ^ ) ( ))updates completion:(nullable void ( ^ ) ( BOOL finished ))completion
Parameters
updates |
The block that performs the relevant insert, delete, reload, or move operations. |
---|---|
completion |
A completion handler block to execute when all of the operations are finished. This block takes a single Boolean parameter that contains the value YES if all of the related animations completed successfully or NO if they were interrupted. This parameter may be nil. If supplied, the block is run on the main thread. |
Declared In
ASCollectionNode.h
– waitUntilAllUpdatesAreCommitted
Blocks execution of the main thread until all section and item updates are committed to the view. This method must be called from the main thread.
- (void)waitUntilAllUpdatesAreCommitted
Declared In
ASCollectionNode.h
– insertSections:
Inserts one or more sections.
- (void)insertSections:(NSIndexSet *)sections
Parameters
sections |
An index set that specifies the sections to insert. |
---|
Discussion
This method must be called from the main thread. The data source must be updated to reflect the changes before this method is called.
Declared In
ASCollectionNode.h
– deleteSections:
Deletes one or more sections.
- (void)deleteSections:(NSIndexSet *)sections
Parameters
sections |
An index set that specifies the sections to delete. |
---|
Discussion
This method must be called from the main thread. The data source must be updated to reflect the changes before this method is called.
Declared In
ASCollectionNode.h
– reloadSections:
Reloads the specified sections.
- (void)reloadSections:(NSIndexSet *)sections
Parameters
sections |
An index set that specifies the sections to reload. |
---|
Discussion
This method must be called from the main thread. The data source must be updated to reflect the changes before this method is called.
Declared In
ASCollectionNode.h
– moveSection:toSection:
Moves a section to a new location.
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection
Parameters
section |
The index of the section to move. |
---|---|
newSection |
The index that is the destination of the move for the section. |
Discussion
This method must be called from the main thread. The data source must be updated to reflect the changes before this method is called.
Declared In
ASCollectionNode.h
– insertItemsAtIndexPaths:
Inserts items at the locations identified by an array of index paths.
- (void)insertItemsAtIndexPaths:(NSArray<NSIndexPath*> *)indexPaths
Parameters
indexPaths |
An array of NSIndexPath objects, each representing an item index and section index that together identify an item. |
---|
Discussion
This method must be called from the main thread. The data source must be updated to reflect the changes before this method is called.
Declared In
ASCollectionNode.h
– deleteItemsAtIndexPaths:
Deletes the items specified by an array of index paths.
- (void)deleteItemsAtIndexPaths:(NSArray<NSIndexPath*> *)indexPaths
Parameters
indexPaths |
An array of NSIndexPath objects identifying the items to delete. |
---|
Discussion
This method must be called from the main thread. The data source must be updated to reflect the changes before this method is called.
Declared In
ASCollectionNode.h
– reloadItemsAtIndexPaths:
Reloads the specified items.
- (void)reloadItemsAtIndexPaths:(NSArray<NSIndexPath*> *)indexPaths
Parameters
indexPaths |
An array of NSIndexPath objects identifying the items to reload. |
---|
Discussion
This method must be called from the main thread. The data source must be updated to reflect the changes before this method is called.
Declared In
ASCollectionNode.h
– moveItemAtIndexPath:toIndexPath:
Moves the item at a specified location to a destination location.
- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath
Parameters
indexPath |
The index path identifying the item to move. |
---|---|
newIndexPath |
The index path that is the destination of the move for the item. |
Discussion
This method must be called from the main thread. The data source must be updated to reflect the changes before this method is called.
Declared In
ASCollectionNode.h
– reloadDataWithCompletion:
Reload everything from scratch, destroying the working range and all cached nodes.
- (void)reloadDataWithCompletion:(nullable void ( ^ ) ( ))completion
Parameters
completion |
block to run on completion of asynchronous loading or nil. If supplied, the block is run on the main thread. |
---|
Discussion
Warning: This method is substantially more expensive than UICollectionView’s version.
Declared In
ASCollectionNode.h
– reloadData
Reload everything from scratch, destroying the working range and all cached nodes.
- (void)reloadData
Discussion
Warning: This method is substantially more expensive than UICollectionView’s version.
Declared In
ASCollectionNode.h
– relayoutItems
Triggers a relayout of all nodes.
- (void)relayoutItems
Discussion
This method invalidates and lays out every cell node in the collection view.
Declared In
ASCollectionNode.h
indexPathsForSelectedItems
The index paths of the selected items, or @c nil if no items are selected.
@property (nonatomic, readonly, nullable) NSArray<NSIndexPath*> *indexPathsForSelectedItems
Declared In
ASCollectionNode.h
– selectItemAtIndexPath:animated:scrollPosition:
Selects the item at the specified index path and optionally scrolls it into view.
If the allowsSelection
property is NO, calling this method has no effect. If there is an existing selection with a different index path and the allowsMultipleSelection
property is NO, calling this method replaces the previous selection.
This method does not cause any selection-related delegate methods to be called.
- (void)selectItemAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition
Parameters
indexPath |
The index path of the item to select. Specifying nil for this parameter clears the current selection. |
---|---|
animated |
Specify YES to animate the change in the selection or NO 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 |
Discussion
This method must be called from the main thread.
Declared In
ASCollectionNode.h
– deselectItemAtIndexPath:animated:
Deselects the item at the specified index. If the allowsSelection property is NO, calling this method has no effect. This method does not cause any selection-related delegate methods to be called.
- (void)deselectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated
Parameters
indexPath |
The index path of the item to select. Specifying nil for this parameter clears the current selection. |
---|---|
animated |
Specify YES to animate the change in the selection or NO to make the change without animating it. |
Discussion
This method must be called from the main thread.
Declared In
ASCollectionNode.h
– numberOfItemsInSection:
Retrieves the number of items in the given section.
- (NSInteger)numberOfItemsInSection:(NSInteger)section
Parameters
section |
The section. |
---|
Return Value
The number of items.
Declared In
ASCollectionNode.h
numberOfSections
The number of sections.
@property (nonatomic, readonly) NSInteger numberOfSections
Declared In
ASCollectionNode.h
visibleNodes
Similar to -visibleCells.
@property (nonatomic, readonly) NSArray<__kindofASCellNode*> *visibleNodes
Return Value
an array containing the nodes being displayed on screen. This must be called on the main thread.
Declared In
ASCollectionNode.h
– nodeForItemAtIndexPath:
Retrieves the node for the item at the given index path.
- (nullable __kindof ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath
Parameters
indexPath |
The index path of the requested item. |
---|
Return Value
The node for the given item, or @c nil if no item exists at the specified path.
Declared In
ASCollectionNode.h
– indexPathForNode:
Retrieve the index path for the item with the given node.
- (nullable NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode
Parameters
cellNode |
A node for an item in the collection node. |
---|
Return Value
The indexPath for this item.
Declared In
ASCollectionNode.h
indexPathsForVisibleItems
Retrieve the index paths of all visible items.
@property (nonatomic, readonly) NSArray<NSIndexPath*> *indexPathsForVisibleItems
Return Value
an array containing the index paths of all visible items. This must be called on the main thread.
Declared In
ASCollectionNode.h
– indexPathForItemAtPoint:
Retrieve the index path of the item at the given point.
- (nullable NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point
Parameters
point |
The point of the requested item. |
---|
Return Value
The indexPath for the item at the given point. This must be called on the main thread.
Declared In
ASCollectionNode.h
– cellForItemAtIndexPath:
Retrieve the cell at the given index path.
- (nullable UICollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath
Parameters
indexPath |
The index path of the requested item. |
---|
Return Value
The cell for the given index path. This must be called on the main thread.
Declared In
ASCollectionNode.h
– contextForSection:
Retrieves the context object for the given section, as provided by the data source in the @c collectionNode:contextForSection: method.
- (nullable id<ASSectionContext>)contextForSection:(NSInteger)section
Parameters
section |
The section to get the context for. |
---|
Return Value
The context object, or @c nil if no context was provided.
TODO: This method currently accepts @c section in the view index space, but it should be in the node index space. To get the context in the view index space (e.g. for subclasses of @c UICollectionViewLayout, the user will call the same method on @c ASCollectionView.
Declared In
ASCollectionNode.h