Ios “奇怪的错误”;选择器'的类方法未知;场景尺寸:'&引用;

Ios “奇怪的错误”;选择器'的类方法未知;场景尺寸:'&引用;,ios,objective-c,ipad,sprite-kit,Ios,Objective C,Ipad,Sprite Kit,我最近开始使用Sprite Kit,现在我刚刚打开了一个新的Sprite Kit项目,删除了MyScene类,因为我不需要它。然后,我创建了自己的SKView子类,名为physisscene,现在当我这样做并替换ViewController.m中的代码时,我在ViewController.m中的第24行出现了这个错误:选择器“sceneWithSize:”没有已知的类方法。下面是我希望更改的所有类文件你可以告诉我发生了什么: ViewController.m 物理场景 查看文档,sceneWit

我最近开始使用Sprite Kit,现在我刚刚打开了一个新的Sprite Kit项目,删除了
MyScene
类,因为我不需要它。然后,我创建了自己的SKView子类,名为
physisscene
,现在当我这样做并替换
ViewController.m
中的代码时,我在
ViewController.m
中的第24行出现了这个错误:
选择器“sceneWithSize:”没有已知的类方法。
下面是我希望更改的所有类文件你可以告诉我发生了什么:

ViewController.m 物理场景
查看文档,sceneWithSize是SKScene的一个类方法,而不是SKView。

PhysicScene
SKView
的一个子类。看起来
physicscene
应该是
SKScene
的子类。解决方案是将
PhysicsScene
转换为的子类,因为您希望使用它。

PhysicsScene接口(可能在PhysicsScene.h中)是否包含+(id)sceneWithSize:(CGSize)size?听起来好像没有。@danh没有,但是我为sprite kit创建的另一个项目也没有包含它,但是编译时没有任何编译错误,而且sceneWithSize不应该手动输入,因为它在创建项目时已经存在
#import "ViewController.h"
#import "PhysicsScene.h"

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Configure the view.
    SKView * skView = (SKView *)self.view;
    skView.showsFPS = YES;
    skView.showsNodeCount = YES;

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

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

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    } else {
        return UIInterfaceOrientationMaskAll;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

@end
#import "PhysicsScene.h"

@implementation PhysicsScene

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end