我正在开发一个 iphone 应用程序,从 CCMenu 中删除所有项目时遇到问题。问题是当调用 CCMenuItem 的选择器时,我删除了触发选择器的项目并且应用程序崩溃了。
代码(在 CCLayer 中):
-(void) clearAll
{
[popupMenu removeAllChildrenWithCleanup:YES];
}
-(void) onButtonClick:(id) sender
{
[self clearAll];
}
-(void) createButtons
{
CCMenuItemImage * menuItem = [CCMenuItemImage itemFromNormalImage:@"back_button.png" selectedImage:@"back_button.png" target:self selector:@selector(onButtonClick:)];
[popupMenu addChild: menuItem];
}
有谁知道为什么应用程序崩溃,我该如何解决这个问题?
谢谢
更新:
崩溃消息堆栈跟踪:
0x01abaabc in __NSI3 ()
0x01a9f495 in -[NSInvocation invoke] ()
0x0006852f in -[CCMenuItem activate] at /***/cocos2d/CCMenuItem.m:128
0x00068d80 in -[CCMenuItemLabel activate] at /***/cocos2d/CCMenuItem.m:222
0x00065c24 in -[CCMenu ccTouchEnded:withEvent:] at /***/cocos2d/CCMenu.m:196
0x01b3ae99 in -[NSObject performSelector:withObject:withObject:] ()
0x000bb44d in -[CCTouchDispatcher touches:withEvent:withTouchType:] at /***/cocos2d/Platforms/iOS/CCTouchDispatcher.m:268
0x000bbfa3 in -[CCTouchDispatcher touchesEnded:withEvent:] at /***/cocos2d/Platforms/iOS/CCTouchDispatcher.m:337
0x000bdd5e in -[EAGLView touchesEnded:withEvent:] at /***/cocos2d/Platforms/iOS/EAGLView.m:330
0x009d63c0 in -[UIWindow _sendTouchesForEvent:] ()
0x009d65e6 in -[UIWindow sendEvent:] ()
0x009bcdc4 in -[UIApplication sendEvent:] ()
0x009b0634 in _UIApplicationHandleEvent ()
0x03589ef5 in PurpleEventCallback ()