--- title: UICollectionViewCell Interoperability layout: docs permalink: /docs/uicollectionviewinterop.html prevPage: placeholder-fade-duration.html nextPage: accessibility.html --- Texture's `ASCollectionNode` offers compatibility with synchronous, standard `UICollectionViewCell` objects alongside native `ASCellNodes`. Note that these UIKit cells will **not** have the performance benefits of `ASCellNodes` (like preloading, async layout, and async drawing), even when mixed within the same `ASCollectionNode`. However, this interoperability allows developers the flexibility to test out the framework without needing to convert all of their cells at once. ## Implementing Interoperability In order to use this feature, you must:
ASCollectionDataSourceInterop
and, optionally, ASCollectionDelegateInterop
.registerCellClass:
on the collectionNode.view
(in viewDidLoad
, or register an onDidLoad:
block).nodeBlockForItem...:
or nodeForItem...:
method. Note: it is an error to return nil from within a nodeBlock
, if you have returned a nodeBlock
object.UICollectionViewFlowLayout
(incl. ASPagerNode
). Implement
collectionNode:constrainedSizeForItemAtIndexPath:
..view.layoutInspector
and have it implement
collectionView:constrainedSizeForNodeAtIndexPath:
..dequeuesCellsForNodeBackedItems
is enabled, then the interop data source will always be consulted to dequeue cells, and will be expected to return _ASCollectionViewCells
in cases where a node was provided.
## CustomCollectionView Example App
The [CustomCollectionView](https://github.com/texturegroup/texture/tree/master/examples/CustomCollectionView) example project demonstrates how to use raw `UIKit` cells alongside native `ASCellNodes`.
Open the app and verify that `kShowUICollectionViewCells` is enabled in `Sample/ViewController.m`.
For this example, the data source method `collectionNode:nodeBlockForItemAtIndexPath:` is setup to return nil for every third cell. When nil is returned, `ASCollectionNode` will automatically query the `cellForItemAtIndexPath:` data source method.
- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode
nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (kShowUICollectionViewCells && indexPath.item % 3 == 1) {
// When enabled, return nil for every third cell and then
// cellForItemAtIndexPath: will be called.
return nil;
}
UIImage *image = _sections[indexPath.section][indexPath.item];
return ^{
return [[ImageCellNode alloc] initWithImage:image];
};
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
return [_collectionNode.view dequeueReusableCellWithReuseIdentifier:kReuseIdentifier
forIndexPath:indexPath];
}