带有 SpriteKit 的 UITableView

UITableView with SpriteKit

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

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

您可以使用didMoveToView中的view

-(void)didMoveToView:(SKView *)view {
    // your table code
    [view addSubview:myTable];
}

使用 SKView 的视图是这里的关键。

如果您使用的是另一种没有 SKView 视图的方法,您可以这样做:

-(void)myMethod {
    SKView* view = self.view;
    // your table code
    [view addSubview:myTable];
}

如果你想在你的场景中使用你的 UITableView(它是在情节提要中创建的,你说出口所以我猜那是你创建它的地方)你需要做一些事情。

首先为场景中的 table 视图创建一个变量。我的 swift 已经生锈了,但如果它是 Objective-C,那就需要在 YourScene.h 文件中创建一个 属性。

现在,当您实例化场景时,您可以设置 table 视图,您在场景中有一个出口。像这样...

scene.tableView = tableView
skView.presentScene(scene)

您希望在您的场景中实现的下一件事 UITableViewDelegate, UITableViewDataSource 这样在您的场景中 didMoveToView 您可以这样做...

tableView?.delegate = self;
tableView?.dataSource = self;

现在在你的场景中你会

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
func cellForRowAtIndexPath(indexPath: NSIndexPath) -> UITableViewCell?

这应该允许您在场景代码中使用 tableView 执行任何操作。

请记住 UITableView 是 UIKit 的一部分,很可能位于您的 SKView 之上(作为子项添加)。定位和大小将在 UIKit 坐标系中。

希望这说得通并且有所帮助。