objective-c - iPad 应用程序因 NSInvalidArgumentException 而崩溃

标签 objective-c ios xcode

我正在尝试制作我的第一个 cocos2d,花栗鼠 ipad 应用程序

我在我的 .h 文件中设置了一个“球” Sprite ,如下所示:

 // HelloWorld Layer 
 @interface
 HelloWorld : CCLayer {     
    cpSpace  *space;
    CCSprite *ball;     
 }

我像这样移动它(触摸):

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    for( UITouch *touch in touches ) {
        CGPoint location = [touch locationInView: [touch view]];

        location = [[CCDirector sharedDirector] convertToGL: location];         

        // Determine speed of the target
        int minDuration = 2.0;
        int maxDuration = 4.0;
        int rangeDuration = maxDuration - minDuration;
        int actualDuration = (arc4random() % rangeDuration) + minDuration;

        // Create the actions
        id actionMove = [CCMoveTo actionWithDuration:actualDuration 
                                            position:ccp(location.x, location.y)];
        id actionMoveDone = [CCCallFuncN actionWithTarget:self 
                                                 selector:@selector(spriteMoveFinished:)];
        [ball runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];

        [ball retain]; 
    }
}

当我使用调试器运行时,我得到了这个:

2011-06-29 20:44:04.121 ballgame[3499:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HelloWorld spriteMoveFinished:]: unrecognized selector sent to instance 0x605a3e0'

它似乎工作了几次,然后似乎崩溃了,所以可能是它的内存泄漏?任何建议或建议都会很有帮助,这就像我的第一个应用程序。

干杯!

最佳答案

您正在对不存在的 HelloWorld 对象调用方法 (spriteMoveFinished:)。您是否制作了 spriteMoveFinished: 方法?

'Unrecognized selector sent' = 调用不存在的方法。

关于objective-c - iPad 应用程序因 NSInvalidArgumentException 而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6529498/

相关文章:

ios - 在 iOS 8 模拟器上操作应用程序权限

ios - 为什么我的静态库会出现 iOS 链接器错误?

iOS Instagram 每次登录问题

iphone - 获取开始日期和结束日期之间的所有 NSDates

ios - SceneKit - 在任何比例下绘制具有相等线宽的缩放圆

objective-c - Objective-C 中的简单自然语言解析器

ios Autolayout - 在图像上对齐文本

ios - 如何防止我的用户从 iPod 中删除 MP3 文件

xcode - swift 中的 AVRecorder 和 AVPlayer

ios - Xcode 10 本地化