Lenny Magico
Lenny Magico

Reputation: 1203

IF UIButton was pressed Xcode

Is it possible to have an if statement that looks if a button has been pressed?

if(condition) {
  //Do something
}

What has to go as the condition?

Upvotes: 1

Views: 6991

Answers (1)

vikingosegundo
vikingosegundo

Reputation: 52237

A UIButton will call a method, to which it is wired up in Interface Builder or set to in code.

If you need to know in certain parts of your program, if a button was pressed, you can do something like this:

-(IBAction)buttonTapped:(UIButton *) sender
{
    self.buttonPressed = YES; //bool instance variable with property
}

-(void)someOtherMethod
{
    if(self.buttonPressed){
        //do what you want to do, if button pressed
    }
}

But I think, coupling the UI and logic so tight on a semantic level, is no good idea.

Upvotes: 4

Related Questions