我有以下控制人
class CategoriesViewController: ASViewController<ASTableNode>, CategoriesViewProtocol {
override init(nibName: String?, bundle: Bundle?) {
super.init(node: ASTableNode())
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
node.dataSource = self
node.delegate = self
}
}
extension CategoriesViewController: ASTableDataSource, ASTableDelegate {
func tableNode(_ tableNode: ASTableNode, numberOfRowsInSection section: Int) -> Int {
return 13
}
func tableView(_ tableView: ASTableView, nodeForRowAt indexPath: IndexPath) -> ASCellNode {
let node = CategoryCell()
return node
}
}
class CategoryCell: ASCellNode {
var name: ASTextNode?
init() {
super.init()
self.name = ASTextNode()
name?.attributedText = NSAttributedString(string: "Hello!", attributes: [NSAttributedStringKey.font: UIFont(name: "HelveticaNeue", size: 12.0)])
}
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let verticalStack = ASStackLayoutSpec.vertical()
verticalStack.children = [ASInsetLayoutSpec(insets: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10), child: self.name!)]
return verticalStack
}
}
但是表格显示为空白
我在做什么错了?
答案 0 :(得分:0)
在您的CategoryCell的init方法中,您必须添加以下内容:
addSubnode(name!)
因此您的类别单元格将如下所示:
class CategoryCell: ASCellNode {
var name: ASTextNode?
init() {
super.init()
self.name = ASTextNode()
addSubnode(name!)
name?.attributedText = NSAttributedString(string: "Hello!", attributes: [NSAttributedStringKey.font: UIFont(name: "HelveticaNeue", size: 12.0)])
}
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let verticalStack = ASStackLayoutSpec.vertical()
verticalStack.children = [ASInsetLayoutSpec(insets: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10), child: self.name!)]
return verticalStack
}