Question

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.

Was it helpful?

Solution

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()
}

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top