How to change the image of a button?

im gets an EXC_BAD_ACCESS error on this line.

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

Basically, I'm just trying to change the normal CCMenuItemSprite image. normalSprite3 and selectedSprte3 are CCSprite. and I removed the properties to save them, but it still always crashes on the above line. Is there an easier way to do what I'm trying to accomplish? basically, set the button to switch? and it changes the image every time you press

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];

Thanks for any help G

+3
source share
1 answer

Why not just

[profile3MenuItem setNormalImage:normalSprite3];

, profileSelectionMenu, getChildByTag ?

UPDATE: , EXC_BAD_ACCESS

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

, , NSZombiesEnabled

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

+1

Source: https://habr.com/ru/post/1757819/


All Articles