ios - nodeBlockForRowAtIndexPath 中的异步调用

标签 ios swift asyncdisplaykit

我在我的 IOS 应用程序中使用异步,并且需要 CollectionView 的流畅滚动,因此我尝试使用 ASyncDisplayKit,它似乎可以平滑滚动。

所有示例都是用ObjectiveC编写的,我想翻译这部分代码:

- (ASCellNodeBlock)tableView:(ASTableView *)tableView    nodeBlockForRowAtIndexPath:(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;
}

谁能帮我用 Swift 翻译这段代码?

最佳答案

在不了解有关 API 的更多信息的情况下,该函数似乎想要返回一个不带参数的 block ,该 block 返回一个 ASCellNode

func tableView(tableView: UITableView, nodeBlockForRowAtIndexPath indexPath: NSIndexPath) -> ASCellNodeBlock {

    let photoModel = photoFeed[indexPath.row]

    let cellNodeBlock:() -> AScellNode = {
        let cellNode = PhotoCellNode(photoObject: photoModel)
        return cellNode
    }

    return cellNodeBlock
}

并且来自 easily searchable docs ...

These two methods, need to return either an ASCellNode or an ASCellNodeBlock. An ASCellNodeBlock is a block that creates a ASCellNode which can be run on a background thread. Note that ASCellNodes are used by ASTableNode, ASCollectionNode and ASPagerNode.

关于ios - nodeBlockForRowAtIndexPath 中的异步调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38293684/

相关文章:

swift - 您可以在 Xcode Playgrounds 中运行 KVC 函数吗?

ios - 文本显示不正确。该功能的文本应放置在屏幕中央

ios - 调用 plist 的子项

ios - 构建正在从 iTunes 连接中消失

ios - 无法在 iOS 13 中设置标签栏阴影图像

swift - 如何设置子 ASNetworkImageNode 的比例

swift - 如何显示 ASNetworkImageNode 的事件指示器?

ios - 我怎样才能重新加载 View iOS swift,MFMailComposeViewController

ios - 让 MKLocalSearch 只返回位置