Search code examples
objective-csprite-kitviewcontrollersksceneskview

Crash calling a ViewController implementing a SpriteKit scene


I am trying to call a viewcontrollerB from a viewcontrollerA with the following code:

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

Within the viewcontrollerB I have the following code:

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]; 

I receive the error:

[UIView setShowsFPS:]: unrecognized selector sent to instance

So I have read and implemented the solution wrote in the following link:

Simple Sprite Kit Scene setup going wrong

But I have the same error.


Solution

  • I have solved with the following code:

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