TableNode 1.0.0

TableNode 1.0.0

Maintained by Ramรณn Dias.



TableNode 1.0.0

TableNode

A TableView made of SpriteKit's Node.

How can you use it?

  1. You must import the TableNodeto your SKScene's class.
import TableNode
  1. Create a variable of type TableNode, in the instance, you should set the frame and view. Later, set it's Delegate and DataSource to self.
var tableNode: TableNode!
  
override func didMove(to view: SKView) {
  self.tableNode = TableNode(frame: CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height), view: self.view!)
    
  self.tableNode.delegate = self
  self.tableNode.dataSource = self
    
  self.addChild(self.tableNode)
}
  • If you want, and I encourage you to do so. Set some position to your TableNode.
var tableNode: TableNode!
  
override func didMove(to view: SKView) {
  self.tableNode = TableNode(frame: CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height), view: self.view!)
    
  self.tableNode.delegate = self
  self.tableNode.dataSource = self
  self.tableNode.position = CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.5)
    
  self.addChild(self.tableNode)
}
  1. Implement the Delegate's methods:
extension GameScene: TableNodeDelegate {
    func tableNode(_ tableNode: TableNode, didSelectCell: TableNodeCell, at: IndexPath) {
        print("\(String(describing: didSelectCell.name))")
    }
}
  1. Implement the DataSource's methods:
extension GameScene: TableNodeDataSource {
    func numberOfRows(inSection section: Int) -> Int {
        return array.count
    }
    
    func tableNode(_ tableNode: TableNode, rowHeight indexPath: IndexPath) -> CGFloat {
        return 100
    }
    
    func tableNode(_ tableNode: TableNode, cellForRowAt indexPath: IndexPath) -> TableNodeCell {
        let cell = tableNode.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        cell.addChild(nodes[indexPath.row])
        return cell
    }
}
  1. Everything is working. ๐ŸŽ‰

If you have any doubt about how TableNode works, you can get help here: Wiki

Disclaimer: The TableNode has more methods than was shown here. And I write about then on Git's Wiki. They have default implementation, and works fine in this way. But, in the future, I expect to make the TableNode more customable. ๐Ÿ‘๐Ÿฝ