【问题标题】:Crash calling a ViewController implementing a SpriteKit scene调用实现 SpriteKit 场景的 ViewController 时崩溃
【发布时间】:2014-10-24 22:15:37
【问题描述】:

我正在尝试使用以下代码从 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

但我有同样的错误。

【问题讨论】:

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


    【解决方案1】:

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

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

    ...您告诉编译器您的视图是SKView,但显然不是。错误消息说这是一个普通的UIView。您需要查看MSPageViewControllerB 是如何定义的,以及它的view 属性定义为什么类型的对象。

    【讨论】:

      【解决方案2】:

      我已经用下面的代码解决了:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-05-12
        • 1970-01-01
        • 2014-08-19
        • 2017-12-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多