[英]UITableView with SpriteKit
How can I implement a UITableView with spriteKit? 如何使用spriteKit实现UITableView? I know that I have create the tableView as an outlet in the ViewController file, but how can I access this tableView from my gameScene so I can change the position, size, cell content etc.
我知道我已经在ViewController文件中将tableView创建为出口,但是如何从我的gameScene访问此tableView以便更改位置,大小,单元格内容等。
I have so far not been able to find any useful instructions or documentation regarding this situation. 到目前为止,我无法找到有关这种情况的任何有用的说明或文档。
If you want to use your UITableView (that was created in a storyboard, you said outlet so I am guessing that is where you created it) within your scene you will need to do a few things. 如果要在场景中使用UITableView(在情节提要中创建的UITableView,您说的是插座,所以我想这是您在其中创建的位置),您需要做一些事情。
First create a variable for your table view in your scene. 首先为场景中的表视图创建一个变量。 My swift is rusty, but if it was Objective-C it would be a matter of creating a property in the YourScene.h file.
我的工作步履蹒跚,但是如果是Objective-C,那就要在YourScene.h文件中创建一个属性。
Now when you instantiate your scene you can set the table view you have an outlet for in your scene. 现在,当您实例化场景时,可以设置表视图,您在场景中有一个插座。 Something like this...
像这样
scene.tableView = tableView
skView.presentScene(scene)
Next thing in your scene you would want to implement UITableViewDelegate, UITableViewDataSource
That way in your didMoveToView
in your scene you can do this... 场景中的下一件事,您将要实现
UITableViewDelegate, UITableViewDataSource
这样,您didMoveToView
在场景中的didMoveToView
中执行此操作...
tableView?.delegate = self;
tableView?.dataSource = self;
Now in your scene you would have 现在在您的场景中,您将拥有
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
func cellForRowAtIndexPath(indexPath: NSIndexPath) -> UITableViewCell?
This should allow you to do anything you would do with a tableView within your scene code. 这应该使您可以执行场景代码中对tableView所做的任何操作。
Just remember a UITableView is part of UIKit and will likely be sitting on top of your SKView (added as a child). 请记住,UITableView是UIKit的一部分,很可能位于您的SKView顶部(作为孩子添加)。 Positioning and size will be in the UIKit coordinate system.
位置和大小将在UIKit坐标系中。
Hopefully that makes sense and is helpful. 希望这是有意义的,并且会有所帮助。
You can use the view in the didMoveToView 您可以在didMoveToView中使用该视图
-(void)didMoveToView:(SKView *)view {
// your table code
[view addSubview:myTable];
}
Using view of SKView being the key here. 使用SKView的视图是这里的关键。
If you are in another method which does not have the SKView view, you can do this: 如果您使用的是另一种没有SKView视图的方法,则可以执行以下操作:
-(void)myMethod {
SKView* view = self.view;
// your table code
[view addSubview:myTable];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.