1

It there a way to use both UITableViewCell and ASCellNode in the same UITableView ?

I have many cells but only some of them have performance issues and AsyncDisplayKit works very well with them. I'm wondering if I have to convert all my UITableViewCell's subclasses in order to use them in an ASTableView.

Gonzo Oin
  • 369
  • 2
  • 12
  • Try to subclass `ASCellNode` – zc246 Apr 20 '16 at 09:05
  • @zcui93 it's not working. The cell is empty and have a zero height, exactly like an empty ASCellNode subclass, which is completely logical because it don't have any subnode. – Gonzo Oin Apr 20 '16 at 09:12
  • Do u tray init ASCellnode from `- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock` ? viewBlock must return ur UITableView ? – Bimawa Nov 24 '16 at 06:31

1 Answers1

0

I've got it working using this initializer in AsyncDisplayKit v2.4, Swift:

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

Here's a working example:

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
}

I have also tried using the view block instead of view controller block that did not work.. the block never got executed:

ASCellNode(viewBlock: { () -> UIView })
Yasha
  • 1,017
  • 11
  • 21