繁体   English   中英

AsyncDisplayKit AsViewController和Swift 3

[英]AsyncDisplayKit AsViewController and swift 3

试图在Swift 3中第一次使用AsyncdisplayKit

有一些我不明白的地方:

我只是设置我的ASviewController:

   final class NodeFeedViewController: ASViewController<ASDisplayNode>, ASTableDataSource, ASTableDelegate {

var tableNode: ASTableNode {
    return node as! ASTableNode
}

init() {
    super.init(node: ASTableNode())
    self.node.view.backgroundColor = UIColor.purple
    self.node.backgroundColor = UIColor.yellow
    self.tableNode.delegate = self
    self.tableNode.dataSource = self
}
required init?(coder aDecoder: NSCoder) {
    fatalError("storyboards are incompatible with truth and beauty")
}

然后我设置了ASTableNode:

func tableNode(tableNode: ASTableNode, nodeForRowAtIndexPath indexPath: NSIndexPath) -> ASCellNode {

    let rowCount = 15

    let node = ASTextCellNode()
    node.text = String(format: "[%ld.%ld] says hello!", indexPath.section, indexPath.row)

    return node
}

func numberOfSectionsInTableNode(tableNode: ASTableNode) -> Int {
    return 1
}

func tableNode(tableNode: ASTableNode, numberOfRowsInSection section: Int) -> Int {
    var count = 16
    return count
}

问题是我编译是因为Xcode告诉我我的控制器不符合协议“ ASCommon TableViewDataSource”,使其工作的唯一方法是添加本机:

/*
@available(iOS 2.0, *)
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}*

/

知道为什么它不能在我的项目上运行并且为什么可以在AsyncdisplayKit的快速示例项目上运行吗? 谢谢你的帮助。

首先:您需要将ViewController()放入AppDelegate

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    let window = UIWindow(frame: UIScreen.main.bounds)
    window.backgroundColor = UIColor.white
    window.rootViewController = UINavigationController(rootViewController: ViewController());
    window.makeKeyAndVisible()
    self.window = window
    return true
}

* ViewController()是包含表的控制器的名称。

第二:检查您的MainStoryboard是否没有关联的视图控制器,如果已关联,则仅清除该字段。

第三:别忘了在您的项目中安装Pod。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM