ASCollectionView Class Reference

Inherits from UICollectionView
Declared in ASCollectionView.h

Overview

Asynchronous UICollectionView with Intelligent Preloading capabilities.

ASCollectionNode is recommended over ASCollectionView. This class exists for adoption convenience.

ASCollectionView is a true subclass of UICollectionView, meaning it is pointer-compatible with code that currently uses UICollectionView.

The main difference is that asyncDataSource expects -nodeForItemAtIndexPath, an ASCellNode, and the sizeForItemAtIndexPath: method is eliminated (as are the performance problems caused by it). This is made possible because ASCellNodes can calculate their own size, and preload ahead of time.

– initWithCollectionViewLayout:

Initializer.

- (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.

Declared In

ASCollectionView.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

ASCollectionView.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

ASCollectionView.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

ASCollectionView.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

ASCollectionView.h

  leadingScreensForBatching

The number of screens left to scroll before the delegate -collectionView:beginBatchFetchingWithContext: is called.

@property (nonatomic, assign) CGFloat leadingScreensForBatching

Discussion

Defaults to two screenfuls.

Declared In

ASCollectionView.h

  layoutInspector

Optional introspection object for the collection view’s layout.

@property (nonatomic, weak) id<ASCollectionViewLayoutInspecting> layoutInspector

Discussion

Since supplementary and decoration views are controlled by the collection view’s layout, this object is used as a bridge to provide information to the internal data controller about the existence of these views and their associated index paths. For collection views using UICollectionViewFlowLayout, a default inspector implementation ASCollectionViewFlowLayoutInspector is created and set on this property by default. Custom collection view layout subclasses will need to provide their own implementation of an inspector object for their supplementary views to be compatible with ASCollectionView’s supplementary node support.

Declared In

ASCollectionView.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 asyncDataSource must be updated to reflect the changes before the update block completes.

- (void)performBatchAnimated:(BOOL)animated updates:(void ( ^ _Nullable ) ( ))updates completion:(void ( ^ _Nullable ) ( BOOL ))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

ASCollectionView.h

– performBatchUpdates:completion:

Perform a batch of updates asynchronously. This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes before update block completes.

- (void)performBatchUpdates:(void ( ^ _Nullable ) ( ))updates completion:(void ( ^ _Nullable ) ( BOOL ))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

ASCollectionView.h

– reloadDataWithCompletion:

Reload everything from scratch, destroying the working range and all cached nodes.

- (void)reloadDataWithCompletion:(void ( ^ _Nullable ) ( ))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

ASCollectionView.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

ASCollectionView.h

– reloadDataImmediately

Reload everything from scratch entirely on the main thread, destroying the working range and all cached nodes.

- (void)reloadDataImmediately

Discussion

Warning: This method is substantially more expensive than UICollectionView’s version and will block the main thread while all the cells load.

Declared In

ASCollectionView.h

– relayoutItems

Triggers a relayout of all nodes.

- (void)relayoutItems

Declared In

ASCollectionView.h

– waitUntilAllUpdatesAreCommitted

Blocks execution of the main thread until all section and row updates are committed. This method must be called from the main thread.

- (void)waitUntilAllUpdatesAreCommitted

Declared In

ASCollectionView.h

– registerSupplementaryNodeOfKind:

Registers the given kind of supplementary node for use in creating node-backed supplementary views.

- (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

ASCollectionView.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 asyncDataSource must be updated to reflect the changes before this method is called.

Declared In

ASCollectionView.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 asyncDataSource must be updated to reflect the changes before this method is called.

Declared In

ASCollectionView.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 asyncDataSource must be updated to reflect the changes before this method is called.

Declared In

ASCollectionView.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 asyncDataSource must be updated to reflect the changes before this method is called.

Declared In

ASCollectionView.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 asyncDataSource must be updated to reflect the changes before this method is called.

Declared In

ASCollectionView.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 asyncDataSource must be updated to reflect the changes before this method is called.

Declared In

ASCollectionView.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 asyncDataSource must be updated to reflect the changes before this method is called.

Declared In

ASCollectionView.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 asyncDataSource must be updated to reflect the changes before this method is called.

Declared In

ASCollectionView.h

– nodeForItemAtIndexPath:

Similar to -cellForItemAtIndexPath:.

- (nullable ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath

Parameters

indexPath

The index path of the requested node.

Return Value

a node for display at this indexpath or nil

Declared In

ASCollectionView.h

– supplementaryNodeForElementKind:atIndexPath:

Similar to -supplementaryViewForElementKind:atIndexPath:

- (nullable ASCellNode *)supplementaryNodeForElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath

Parameters

elementKind

The kind of supplementary node to locate.

indexPath

The index path of the requested supplementary node.

Return Value

The specified supplementary node or nil

Declared In

ASCollectionView.h

– indexPathForNode:

Similar to -indexPathForCell:.

- (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode

Parameters

cellNode

a cellNode part of the table view

Return Value

an indexPath for this cellNode

Declared In

ASCollectionView.h

– visibleNodes

Similar to -visibleCells.

- (NSArray<ASCellNode*> *)visibleNodes

Return Value

an array containing the nodes being displayed on screen.

Declared In

ASCollectionView.h

– calculatedSizeForNodeAtIndexPath:

Query the sized node at indexPath for its calculatedSize.

- (CGSize)calculatedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath

Parameters

indexPath

The index path for the node of interest.

Declared In

ASCollectionView.h

– scrollDirection

Determines collection view’s current scroll direction. Supports 2-axis collection views.

- (ASScrollDirection)scrollDirection

Return Value

a bitmask of ASScrollDirection values.

Declared In

ASCollectionView.h

– scrollableDirections

Determines collection view’s scrollable directions.

- (ASScrollDirection)scrollableDirections

Return Value

a bitmask of ASScrollDirection values.

Declared In

ASCollectionView.h

– clearContents

Triggers all loaded ASCellNodes to destroy displayed contents (freeing a lot of memory).

- (void)clearContents

Discussion

This method should only be called by ASCollectionNode. To be removed in a later release.

Declared In

ASCollectionView.h

– clearFetchedData

Triggers all loaded ASCellNodes to purge any data fetched from the network or disk (freeing memory).

- (void)clearFetchedData

Discussion

This method should only be called by ASCollectionNode. To be removed in a later release.

Declared In

ASCollectionView.h

  zeroContentInsets

Forces the .contentInset to be UIEdgeInsetsZero.

@property (nonatomic) BOOL zeroContentInsets

Discussion

By default, UIKit sets the top inset to the navigation bar height, even for horizontally scrolling views. This can only be disabled by setting a property on the containing UIViewController, automaticallyAdjustsScrollViewInsets, which may not be accessible. ASPagerNode uses this to ensure its flow layout behaves predictably and does not log undefined layout warnings.

Declared In

ASCollectionView.h