开发者

How to change image of a button?

开发者 https://www.devze.com 2023-01-10 05:03 出处:网络
im getting a EXC_BAD_ACCESS error on this line. [(CCMenuItemSprite*)[profileSelectionMenu getChildByTag:333] setNormalImage:normalSprite3];

im getting a EXC_BAD_ACCESS error on this line.

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

Basically im just trying to change 开发者_如何学JAVAthe normal image of a CCMenuItemSprite. normalSprite3 and selectedSprte3 are both CCSprite. and i set the properties off them to retain but it still always crashing on the above line. Is there an easier way to do what im trying to accomplish? basically set the button to be a toggle button? and it changes image everytime it is pressed

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


Why not just

[profile3MenuItem setNormalImage:normalSprite3];

Also, where do you add the item to profileSelectionMenu so that getChildByTag works?

UPDATE: I wrote this to help with debugging EXC_BAD_ACCESS

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

If you think you are releasing early, turn on NSZombiesEnabled

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号