我正在尝试在我的游戏中实现一个非常简单的iAd,我收到了一个错误。我是Xcode的新手,无法读取错误代码。我在一个新的SpriteKit项目中尝试了完全相同的方法,它运行得很好。我猜这必须与我的游戏有关。
错误如下。
2014-03-30 17:18:35.966 MyGame[672:60b] -[UIView setPaused:]: unrecognized selector sent to instance 0xa764120
2014-03-30 17:18:35.970 MyGame[672:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setPaused:]: unrecognized selector sent to instance 0xa764120'
*** First throw call stack:
(
0 CoreFoundation 0x019901e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0170f8e5 objc_exception_throw + 44
2 CoreFoundation 0x01a2d243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0198050b ___forwarding___ + 1019
4 CoreFoundation 0x019800ee _CF_forwarding_prep_0 + 14
5 MyGame 0x00012331 -[AppDelegate applicationDidBecomeActive:] + 225
6 UIKit 0x002a6ca6 -[UIApplication _stopDeactivatingForReason:] + 329
7 UIKit 0x002ac891 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 1378
8 UIKit 0x002c0f92 -[UIApplication handleEvent:withNewEvent:] + 3517
9 UIKit 0x002c1555 -[UIApplication sendEvent:] + 85
10 UIKit 0x002ae250 _UIApplicationHandleEvent + 683
11 GraphicsServices 0x025d9f02 _PurpleEventCallback + 776
12 GraphicsServices 0x025d9a0d PurpleEventCallback + 46
13 CoreFoundation 0x0190bca5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
14 CoreFoundation 0x0190b9db __CFRunLoopDoSource1 + 523
15 CoreFoundation 0x0193668c __CFRunLoopRun + 2156
16 CoreFoundation 0x019359d3 CFRunLoopRunSpecific + 467
17 CoreFoundation 0x019357eb CFRunLoopRunInMode + 123
18 UIKit 0x002abd9c -[UIApplication _run] + 840
19 UIKit 0x002adf9b UIApplicationMain + 1225
20 MyGame 0x0001250d main + 141
21 libdyld.dylib 0x02ad8701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
我的ViewController.m如下
- (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 = [StartGameScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
self.canDisplayBannerAds = YES;
// Present the scene.
[skView presentScene:scene];
}
答案 0 :(得分:0)
尝试在viewWillLayoutSubViews中添加代码......
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = [StartGameScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
self.canDisplayBannerAds = YES;
// Present the scene.
[skView presentScene:scene];
}
答案 1 :(得分:0)
显然,我在原始问题中使用的ViewController.m是正确的。造成这个问题的原因是我在AppDelegate.m中放了几行来暂停游戏。这就是我得到'NSInvalidArgumentException'的原因:' - [UIView setPaused:]:error。
以下是我的AppDelegate.m中包含导致崩溃的行的两种方法。
- (void)applicationWillResignActive:(UIApplication *)application
{
// pause sprite kit
SKView *view = (SKView *)self.window.rootViewController.view;
view.paused = YES;
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
//resume sprite kit
SKView *view = (SKView *)self.window.rootViewController.view;
view.paused = NO;
}
我删除了这4行,一切正常。非常感谢那些帮助过的人。