奇怪的错误“没有选择器的已知类方法'sceneWithSize:'”

时间:2014-01-27 03:46:21

标签: ios objective-c ipad sprite-kit

我最近开始使用Sprite Kit,我刚刚开了一个新的sprite kit项目并删除了MyScene课程,因为我不需要它。我已经创建了自己的SKView子类,名为PhyscisScene,现在当我完成此操作并替换ViewController.m中的代码时,我在第24行 ViewController.mNo known class method for selector 'sceneWithSize:'以下是我所有的班级文件我希望你能告诉我发生了什么:

ViewController.m

#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

PhysicsScene.m

#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

2 个答案:

答案 0 :(得分:3)

PhysicsSceneSKView的子类。看起来PhysicsScene应该是SKScene的子类。解决方案是将PhysicsScene转换为SKScene的子类,因为这就是您想要使用它的目的。

答案 1 :(得分:1)

查看文档,sceneWithSize是SKScene的类方法,而不是SKView。