使用SpriteKit的UITableView

Ree*_*ney 1 uitableview uiview ios sprite-kit swift

如何使用spriteKit实现UITableView?我知道我已经在ViewController文件中创建了tableView作为插座,但是如何从我的gameScene访问这个tableView,这样我就可以改变位置,大小,单元格内容等.

到目前为止,我还没有找到任何有关这种情况的有用说明或文件.

Sky*_*ren 6

如果你想在你的场景中使用你的UITableView(在故事板中创建,你说插座,所以我猜这是你创建它的地方),你需要做一些事情.

首先在场景中为表视图创建一个变量.我的swift很生疏,但如果它是Objective-C,那么就是在YourScene.h文件中创建一个属性的问题.

现在,当您实例化场景时,您可以设置场景中有出口的表格视图.像这样......

scene.tableView = tableView
skView.presentScene(scene)
Run Code Online (Sandbox Code Playgroud)

在你的场景中你想要实现的下一件事你可以在你的场景中实现UITableViewDelegate, UITableViewDataSourcedidMoveToView一点......

tableView?.delegate = self;
tableView?.dataSource = self;
Run Code Online (Sandbox Code Playgroud)

现在你的场景中你会有

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
func cellForRowAtIndexPath(indexPath: NSIndexPath) -> UITableViewCell?
Run Code Online (Sandbox Code Playgroud)

这应该允许您在场景代码中对tableView执行任何操作.

只记得UITableView是UIKit的一部分,可能会坐在您的SKView上(作为孩子添加).定位和大小将在UIKit坐标系中.

希望这是有道理的,也是有帮助的.