2010-08-03 91 views
3

即时在这一行上得到一个EXC_BAD_ACCESS错误。如何更改按钮的图像?

[(CCMenuItemSprite *)[profileSelectionMenu getChildByTag:333] setNormalImage:normalSprite3];

基本上我只是试图改变一个CCMenuItemSprite的正常形象。 normalSprite3和selectedSprte3都是CCSprite。我将它们的属性设置为保留,但它仍然总是在上面的行中崩溃。有没有更简单的方法来做什么即时通讯试图完成?基本上将该按钮设置为切换按钮?而且每次改变图像被压

normalSprite3 =[CCSprite spriteWithFile:@"main_menu_button.png"]; 
selectedSprite3 =[CCSprite spriteWithFile:@"main_menu_button_select.png"]; 



profile3MenuItem = [CCMenuItemImage itemFromNormalSprite:normalSprite3 selectedSprite:selectedSprite3 
                  target:self 
                 selector:@selector(P3:)]; 
     [profile3MenuItem setTag:333]; 

[(CCMenuItemSprite*)[profileSelectionMenu getChildByTag:333] setNormalImage:normalSprite3]; 

感谢所有帮助 摹

回答

1

为什么不

[profile3MenuItem setNormalImage:normalSprite3]; 

而且,当你的项目添加到profileSelectionMenu使getChildByTag的作品?

更新:我写了这个,以帮助调试EXC_BAD_ACCESS

http://loufranco.com/blog/files/Understanding-EXC_BAD_ACCESS.html

如果你认为你是在开发初期发布,打开NSZombiesEnabled

http://loufranco.com/blog/files/debugging-memory-iphone.html

+0

profileSelectionMenu = [CCMenu menuWithItems:profile1MenuItem, profile2MenuItem,profile3MenuItem,profile4MenuItem,profile5MenuItem,nil]; \t \t 是我将菜单项添加到菜单的行。是的,我曾尝试过你建议的结果也一样。他们都工作,如果我有他们在相同的初始化函数,但当我在P3函数中使用该行崩溃。所以有些东西必须在某处被释放,但是我不知道如何使用retain。 – glogic 2010-08-03 13:02:36

+0

帮助找到解除分配的对象(使用NSZombiesEnabled) – 2010-08-03 13:34:10

+0

这完全是我不知道NSZombiesEnabled和其他链接中的其他人。我的一个小精灵正在被dealloc提前,我想,但我是阿尔法缩小和解决这个问题谢谢你太多了! 欢呼声 G – glogic 2010-08-04 10:05:42