Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7960723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:50:09+00:00 2026-06-04T04:50:09+00:00

Ok guys I got a problem with UIButton, maybe that´s simple to solve. I

  • 0

Ok guys I got a problem with UIButton, maybe that´s simple to solve. I have a button with an IBAction toggleMusic which changes the background image.

-(IBAction)toggleMusic{
    if (gameAppDelegate.playMusic) {
        gameAppDelegate.playMusic = NO;
        [menuAudioPlayer stop];
        [botaoMusic setBackgroundImage:[UIImage imageNamed:@"bt_sound_off.png"] forState:UIControlStateNormal];
        [SoundManager playSoundFile:@"botao3" Format:@"wav" InLoop:NO];

    }
    else {
        gameAppDelegate.playMusic = YES;
        [menuAudioPlayer play];
        [botaoMusic setBackgroundImage:[UIImage imageNamed:@"bt_sound_on.png"] forState:UIControlStateNormal];
        [SoundManager playSoundFile:@"botao3" Format:@"wav" InLoop:NO];

    }
}

This is working fine. playmusic (bool) is a stored variable, so everytime I turn the app off and then on, the app already knows if it should play music or not. this is also working fine.

the problem is that I want to set the correct background image (music on/off) as soon as the app is turned on (not only when I click the button). so I put the following code on view will appear:

-(void)viewWillAppear:(BOOL)animated{
    if(gameAppDelegate.playMusic)
        [botaoMusic setImage:[UIImage imageNamed:@"bt_sound_on.png"] forState:UIControlStateNormal];
    else
        [botaoMusic setImage:[UIImage imageNamed:@"bt_sound_off.png"] forState:UIControlStateNormal];


}

when I introduce this code, the app succesfully recognizes the correct background image when the view appears, but togglemusic ceases to alter the button background when I touch the button. It may be something silly, but I can´t figure out what I´m doing wrong…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:50:11+00:00Added an answer on June 4, 2026 at 4:50 am

    The one thing I notice is in viewWillAppear you call

    [botaoMusic setImage:...];
    

    whereas in the button press you call

    [botaoMusic setBackgroundImage:...];
    

    It is likely that it is still functioning, just changing the background image BEHIND the top image of whatever was loaded when the view appears

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi guys Ive got a problem with item renderer.I have a data group that
Guys, I've got this problem that I searched almost everywhere (maybe I don't know
I've got yet another deployment problem. What I have: little Windows Forms application that
i guys i have a problem, i want to run a haskell script that
Hey guys i got a problem which is doing my head in, and was
Hey Guys. I have got a problem on using the jquery auto-complete plugin.my problem
Guys, I have got a slightly different problem with Java Dynamic class loading. I
Hay guys, i need help with a REGEX. I have the got the value
I'm learning Ruby right now and I got stuck, maybe you guys can help
I have got a problem with my codeigniter library. To transform database data into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.