質問

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.

役に立ちましたか?

解決

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

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top