Crash调用实现SpriteKit场景的ViewController

时间:2014-08-31 14:42:24

标签: objective-c sprite-kit viewcontroller skscene skview

我正在尝试使用以下代码从viewcontrollerA调用viewcontrollerB:

ViewControllerB *vc = [[ViewControllerB alloc]initWithNibName:nil bundle:nil];
[self presentViewController:vc animated:YES completion:nil];

在viewcontrollerB中,我有以下代码:

SKView * skView = (SKView *)self.view;

skView.showsFPS = NO;
skView.showsNodeCount = NO;

// Create and configure the scene.
SKScene * scene = [MainScene sceneWithSize:skView.bounds.size];
//scene.scaleMode = SKSceneScaleModeAspectFit;

// Present the scene.
[skView presentScene:scene]; 

我收到错误:

[UIView setShowsFPS:]:无法识别的选择器发送到实例

所以我已经阅读并实现了以下链接中写的解决方案:

Simple Sprite Kit Scene setup going wrong

但我有同样的错误。

2 个答案:

答案 0 :(得分:1)

当你这样做时......

SKView * skView = (SKView *)self.view;

skView.showsFPS = NO;

...你告诉编译器你的视图是SKView,但显然不是。{错误消息表明它是普通的UIView。您需要了解如何定义MSPageViewControllerB以及将view属性定义为什么类型的对象。

答案 1 :(得分:0)

我用以下代码解决了:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
ViewControllerB *viewController = [storyboard instantiateViewControllerWithIdentifier:@"ViewControllerB"];
[self presentViewController:viewController animated:YES completion:nil];