有办法在同一个 UITableView 中同时使用 UITableViewCell 和 ASCellNode 吗?
我有很多单元格,但只有其中一些有性能问题,而且 AsyncDisplayKit 与它们配合得很好。我想知道是否必须转换所有 UITableViewCell 的子类才能在 ASTableView 中使用它们。
有办法在同一个 UITableView 中同时使用 UITableViewCell 和 ASCellNode 吗?
我有很多单元格,但只有其中一些有性能问题,而且 AsyncDisplayKit 与它们配合得很好。我想知道是否必须转换所有 UITableViewCell 的子类才能在 ASTableView 中使用它们。
我已经在 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 })