ASViewController <ASTableNode>показать пустую таблицу - PullRequest
0 голосов
/ 28 июня 2018

У меня следующий контроллер

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
    }

}

Но в таблице пусто

Что я делаю не так?

1 Ответ

0 голосов
/ 02 июля 2018

В методе init вашей CategoryCell вы должны добавить следующее:

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
}
...