使用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;
}
結果:
讓我檢查上,並會盡快給你 – fAiSaL
我換表collectionnode ......現在它perfeclty – fAiSaL