是否可以在ASTableView中使用UItableViewCell?

时间:2016-04-20 08:57:51

标签: ios swift uitableview asyncdisplaykit

有没有办法在同一个UITableView中同时使用UITableViewCell和ASCellNode?

我有很多单元格,但只有部分单元存在性能问题,AsyncDisplayKit与它们配合得非常好。我想知道是否必须转换所有UITableViewCell的子类才能在ASTableView中使用它们。

1 个答案:

答案 0 :(得分:0)

我已经在AsyncDisplayKit v2.4中使用这个初始化程序了,Swift:

ASCellNode(viewControllerBlock: { () -> UIViewController }, didLoad: { (ASDisplayNode) -> Void })

这是一个有效的例子:

func tableNode(_ tableNode: ASTableNode, nodeBlockForRowAt indexPath: IndexPath) - > ASCellNodeBlock {
    let content = self.contentList[indexPath.row]

    // Return the old cell only for specific rows
    if content.type == "MyOldContentThatUsesUITableViewCell" {
        return {
            // Load OldContentCell through a view block on the main thread
            let cellHeight: CGFloat = 367.0
            let cellNode = ASCellNode(viewControllerBlock: { () - > UIViewController in
                let viewController = UIViewController()

                // Load a cell using xib
                guard let cell = Bundle.main.loadNibNamed("OldContentCell", owner: self, options: nil) ? [0] as ? OldContentCell else {
                  return viewController
                }

                // Since it's on the main thread, we can use UIScreen to get the full width
                cell.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: cellHeight)
                viewController.view.addSubview(cell)

                return viewController
            }, didLoad: nil)

            // Width here doesn't really matter.. it will try and expand the cell's width
            // to the ASTableNode's width
            cellNode.style.preferredSize = CGSize(width: 100.0, height: cellHeight)
            return cellNode
        }
    }

    // Return a real ASCellNode totally managed by AsyncDisplayKit
    let cellNodeBlock: () -> ASCellNode = {
        // My subclass of ASCellNode 
        return ContentCellNode(content: content, contentIndex: indexPath.row)
    }

    return cellNodeBlock
}

我也尝试使用视图块而不是视图控制器块,但是没有工作。块永远不会被执行:

ASCellNode(viewBlock: { () -> UIView })