0

I researched on this website but couldn't find anything to help me. I'm a beginner in coding so this may seem simple to some of you but hard for me. I have an instruction button in my game that i press to show a speech bubble giving the user instruction. I am trying to achieve, when I repress the instruction button, the speech bubble should disappear.

.h

IBOutlet UIImageView *instructionsPic;
- (IBAction)instructionAction;

.m

    - (IBAction)instructionAction {
    instructionsPic.hidden = NO;
    startGameButton.hidden = YES;
}

In my viewDidLoad i marked my instruction bubble speech as hidden and when the user hits the instruction button it shows up. So yea, how can i make it disappear again when they click the button again?

1
  • 1
    Check the the property instructionsPic.hidden to see if it is hidden, if so set it to YES. Or simply: instructionsPic.hidden = ! instructionsPic.hidden;
    – zaph
    Commented Jun 27, 2015 at 21:02

1 Answer 1

1

You have to toggle the hidden property of your 'instructionsPic' each time 'instruction' button is pressed.

You can change your IBAction method to :

- (IBAction)instructionAction {
instructionsPic.hidden = !instructionsPic.hidden;
startGameButton.hidden = !startGameButton.hidden;
}

I leave it upto you to understand the logic used here.

3
  • Sweet it worked. I wasn't aware of that ! function. Thank you! I will mark as accepted once i can :) Commented Jun 27, 2015 at 21:08
  • '!' is ' logical Not operator'. It inverts whatever Bool value is given to it. You can read more about it here. cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap03/logical.html.
    – tek3
    Commented Jun 27, 2015 at 21:11
  • 1
    @user3763526 Get a book on the "C" language and study it. Objective-C supports all of C and a lot of other languages are built on much of the same operators and syntax.
    – zaph
    Commented Jun 27, 2015 at 21:18

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.