Domanda

I have an IBAction on a button - when it is pressed the method runs as expected.

In that method I update the text label of the button that was pressed.

What i want to happen is when it is repressed I'd like to check the label of the button AND the fact that it was repressed, any ideas how? I'm currently trying to check the state:

if ([buttonName isEqualToString:@"Done"] && (_airlineSelectButtonLabel.state == UIControlEventTouchUpInside)) {
        //Do whatever
    }

Thanks.

È stato utile?

Soluzione

I dont see from your question how you retrieved the title on your button, make sure you are using:

NSString *strTitleOnButton = [button titleForState:UIControlStateNormal];

But better use selected property of your UIButton to know if pressed unpressed for example:

- (IBAction)buttonClicked:(UIButton *)sender
{
    if (sender.selected)
    {
        //Already Pressed
    }
    else
    {
        //Unpressed
    }
    sender.selected.toggle()
}

Altri suggerimenti

firstly, to get the label of the button use [[sender currentTitle] isEqualToString:@"Done"]; inside your button action.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top