ASCellNode Class Reference

Inherits from ASDisplayNode : ASDealloc2MainObject
Declared in ASCellNode.h

Overview

  • Generic cell node. Subclass this instead of ASDisplayNode to use with ASTableView and ASCollectionView.

  • @note When a cell node is contained inside a collection view (or table view),

  • calling -setNeedsLayout will also notify the collection on the main thread
  • so that the collection can update its item layout if the cell’s size changed.

  neverShowPlaceholders

When enabled, ensures that the cell is completely displayed before allowed onscreen.

@default NO

@property (nonatomic, assign) BOOL neverShowPlaceholders

Discussion

Normally, ASCellNodes are preloaded and have finished display before they are onscreen. However, if the Table or Collection’s rangeTuningParameters are set to small values (or 0), or if the user is scrolling rapidly on a slow device, it is possible for a cell’s display to be incomplete when it becomes visible.

In this case, normally placeholder states are shown and scrolling continues uninterrupted. The finished, drawn content is then shown as soon as it is ready.

With this property set to YES, the main thread will be blocked until display is complete for the cell. This is more similar to UIKit, and in fact makes AsyncDisplayKit scrolling visually indistinguishable from UIKit’s, except being faster.

Using this option does not eliminate all of the performance advantages of AsyncDisplayKit. Normally, a cell has been preloading and is almost done when it reaches the screen, so the blocking time is very short. If the rangeTuningParameters are set to 0, still this option outperforms UIKit: while the main thread is waiting, subnode display executes concurrently.

Declared In

ASCellNode.h

  selected

A Boolean value that is synchronized with the underlying collection or tableView cell property. Setting this value is equivalent to calling selectItem / deselectItem on the collection or table.

@property (nonatomic, assign, getter=isSelected) BOOL selected

Declared In

ASCellNode.h

  highlighted

A Boolean value that is synchronized with the underlying collection or tableView cell property. Setting this value is equivalent to calling highlightItem / unHighlightItem on the collection or table.

@property (nonatomic, assign, getter=isHighlighted) BOOL highlighted

Declared In

ASCellNode.h

  indexPath

The current index path of this cell node, or @c nil if this node is not a valid item inside a table node or collection node.

@property (nonatomic, readonly, nullable) NSIndexPath *indexPath

Discussion

Note: This property must be accessed on the main thread.

Declared In

ASCellNode.h

  owningNode

The owning node (ASCollectionNode/ASTableNode) of this cell node, or @c nil if this node is not a valid item inside a table node or collection node or if those nodes are nil.

@property (weak, nonatomic, readonly, nullable) ASDisplayNode *owningNode

Declared In

ASCellNode.h

– applyLayoutAttributes:

Called by the system when ASCellNode is used with an ASCollectionNode. It will not be called by ASTableNode. When the UICollectionViewLayout object returns a new UICollectionViewLayoutAttributes object, the corresponding ASCellNode will be updated. See UICollectionViewCell’s applyLayoutAttributes: for a full description.

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes

Declared In

ASCellNode.h

– initWithViewControllerBlock:didLoadBlock:

Initializes a cell with a given view controller block.

- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock

Parameters

viewControllerBlock

The block that will be used to create the backing view controller.

didLoadBlock

The block that will be called after the view controller’s view is loaded.

Return Value

An ASCellNode created using the root view of the view controller provided by the viewControllerBlock. The view controller’s root view is resized to match the calculated size produced during layout.

Declared In

ASCellNode.h

– cellNodeVisibilityEvent:inScrollView:withCellFrame:

Notifies the cell node of certain visibility events, such as changing visible rect.

- (void)cellNodeVisibilityEvent:(ASCellNodeVisibilityEvent)event inScrollView:(nullable UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame

Discussion

Warning: In cases where an ASCellNode is used as a plain node – i.e. not returned from the nodeBlockForItemAtIndexPath/nodeForItemAtIndexPath data source methods – this method will deliver only the Visible and Invisible events, scrollView will be nil, and cellFrame will be the zero rect.

Declared In

ASCellNode.h