I'm making a app using Apple's Spritekit framework. My app has multiple view controllers and everything works fine. However, I tried to make a scene that I would load in one of my viewcontrollers, but that did not work. I get no errors at all: it just does not work. Everything works except when I try to load my scene, everything crashes. Also, I was thinking, could my problem be that I have already added a view and put labels and buttons, etc... on that view before I load my scene? To elaborate, could the problem be that I have already added uiimages, etc... to the view using interface builder before I loaded my scene programmatically? Any help would be great. Here is my code for the view controller where I call my scene:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
SKView * skView = (SKView *)self.view;
// Create and configure the scene.
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
And here is my code for the actual scene:
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
/* Setup your scene here */
SKSpriteNode *mainTurrentSprite = [SKSpriteNode spriteNodeWithImageNamed:@"mainTurrent.png"];
mainTurrentSprite.position = CGPointMake(self.view.center.x, 0);
[self addChild:mainTurrentSprite];
}
return self;
}
And here is my crash/error log :
2014-07-22 14:32:34.783 Doodle Defense[6713:60b] -[UIView presentScene:]: unrecognized selector sent to instance 0x9a32630 2014-07-22 14:32:34.786 Doodle Defense[6713:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView presentScene:]: unrecognized selector sent to instance 0x9a32630' *** First throw call stack: ( 0 CoreFoundation 0x019231e4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x0168e8e5 objc_exception_throw + 44 2 CoreFoundation 0x019c0243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275 3 CoreFoundation 0x0191350b ___forwarding___ + 1019 4 CoreFoundation 0x019130ee _CF_forwarding_prep_0 + 14 5 Doodle Defense 0x000020b1 -[GameViewController viewDidLoad] + 337 6 UIKit 0x0034b33d -[UIViewController loadViewIfRequired] + 696 7 UIKit 0x0034b5d9 -[UIViewController view] + 35 8 UIKit 0x0035af89 -[UIViewController shouldAutorotate] + 36 9 UIKit 0x0035b2d1 -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:] + 297 10 UIKit 0x005f93d5 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 2330 11 UIKit 0x003575d5 -[UIViewController presentViewController:withTransition:completion:] + 6538 12 UIKit 0x00357aef -[UIViewController presentViewController:animated:completion:] + 130 13 UIKit 0x00357b2f -[UIViewController presentModalViewController:animated:] + 56 14 UIKit 0x007a1e00 -[UIStoryboardModalSegue perform] + 271 15 UIKit 0x00790f0c -[UIStoryboardSegueTemplate _perform:] + 174 16 UIKit 0x00790f87 -[UIStoryboardSegueTemplate perform:] + 115 17 libobjc.A.dylib 0x016a0880 -[NSObject performSelector:withObject:withObject:] + 77 18 UIKit 0x0022e3b9 -[UIApplication sendAction:to:from:forEvent:] + 108 19 UIKit 0x0022e345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61 20 UIKit 0x0032fbd1 -[UIControl sendAction:to:forEvent:] + 66 21 UIKit 0x0032ffc6 -[UIControl _sendActionsForEvents:withEvent:] + 577 22 UIKit 0x0032f243 -[UIControl touchesEnded:withEvent:] + 641 23 UIKit 0x0026dddd -[UIWindow _sendTouchesForEvent:] + 852 24 UIKit 0x0026e9d1 -[UIWindow sendEvent:] + 1117 25 UIKit 0x002405f2 -[UIApplication sendEvent:] + 242 26 UIKit 0x0022a353 _UIApplicationHandleEventQueue + 11455 27 CoreFoundation 0x018ac77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15 28 CoreFoundation 0x018ac10b __CFRunLoopDoSources0 + 235 29 CoreFoundation 0x018c91ae __CFRunLoopRun + 910 30 CoreFoundation 0x018c89d3 CFRunLoopRunSpecific + 467 31 CoreFoundation 0x018c87eb CFRunLoopRunInMode + 123 32 GraphicsServices 0x039035ee GSEventRunModal + 192 33 GraphicsServices 0x0390342b GSEventRun + 104 34 UIKit 0x0022cf9b UIApplicationMain + 1225 35 Doodle Defense 0x00002add main + 141 36 libdyld.dylib 0x01f56701 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException
User contributions licensed under CC BY-SA 3.0