如何在AsyncDisplayKit中为AsTableNode创建一个框架?

时间:2016-12-29 06:23:03

标签: ios swift facebook asyncdisplaykit

我使用facebook's AsyncDisplayKi来运行我的项目,在那里我找到了一个名为" ASDKgram "的示例项目。它使用节点而不是TableViewCells。默认情况下,' AsTableNodes' aka TableView显示在屏幕的边界。

我希望我的tableViewAsTableNodes在uiScreen的每个边缘显示10pixels

问题:如何使用该特定框架创建AsTableNodes?

如果有人已通过AsyncDisplayKit,请回答。

以下是该项目的链接https://github.com/facebook/AsyncDisplayKit/tree/master/examples/ASDKgram

先谢谢。

1 个答案:

答案 0 :(得分:1)

使用ASCollectionNode

首先,替换

tableNode = [[ASTableNode alloc] init];

tableNode = [[ASCollectionNode alloc] initWithCollectionViewLayout:[UICollectionViewFlowLayout new]];

然后将其添加到ASViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  _tableNode.view.contentInset = UIEdgeInsetsMake(0, 10, 0, 10);
}

- (ASSizeRange)collectionView:(ASCollectionView *)collectionView constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath {
  return ASSizeRangeMake(
          CGSizeMake(0, 0),
          CGSizeMake(self.view.frame.size.width - 2*10, CGFLOAT_MAX)
  );
}

- (NSInteger)collectionNode:(ASCollectionNode *)collectionNode numberOfItemsInSection:(NSInteger)section {
  return [_photoFeed numberOfItemsInFeed];
}

- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath {
  PhotoModel *photoModel = [_photoFeed objectAtIndex:indexPath.row];
  // this will be executed on a background thread - important to make sure it's thread safe
  ASCellNode *(^ASCellNodeBlock)() = ^ASCellNode *() {
      PhotoCellNode *cellNode = [[PhotoCellNode alloc] initWithPhotoObject:photoModel];
      return cellNode;
  };

  return ASCellNodeBlock;
}

结果:

enter image description here