check if UIButton is selected

Go To StackoverFlow.com

4

Is there any way to keep track the state of a UIButton whether it is selected or not? I tried accessing the selected property but it doesn't seem to work, seems to work only for UISwitch

2012-04-05 00:35
by adit
what do you mean selected? It doesnt make sense for a button...a button is either being pushed or existing normally - borrrden 2012-04-05 00:40


8

You need to set the state to selected if you want to use it like a toggle

- (void)buttonTapped:(UIButton *)button;
{
    button.selected = ![button isSelected];
}

then you can just query it like normal

[self.button isSelected];
2012-04-05 00:40
by Paul.s
I wondered [self.button isSelected]; is not working in Xcode 7.2 even i created IBAction and it alway gives me .any help - Avijit Nagare 2016-10-10 10:14


2

Yes some UIButtons can have a selected state, which may only be momentary. However UIButtons inherit from UIControls which have a selected property. You can query to see if you button is selected using:

if([myButton isSelected])
    NSLog(@"Selected!")
2012-04-05 01:00
by Kyle Richter


0

What do you mean by “selected”? In standard usage, UIButtons only have three states: normal, disabled, and active, where “active” means “being tapped right now”. They’re not sticky.

2012-04-05 00:39
by bdesham
It's just a helper boolean value for a button for your own programatic use that is avalable. I use it if I have multiple alerts and I want to know which one was "selected". You do have to control the boolean yourself though - LevinsonTechnologies 2015-06-17 15:53
Ads