Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only allow users to press UIButton once

I am trying to design a interface of an app, and i would only like to allow the user to press a UIButton once to get the result. Is there any way i can lock the button after the button is pressed? And release the lock only when another button is pressed?

Thanks

like image 489
Clarence Avatar asked Dec 07 '22 12:12

Clarence


2 Answers

You can set the button to be disabled once it is clicked:

- (IBAction)clicked:(id)sender {
    //See all buttons enabled
    //Try a loop or manually

    ((UIButton *)sender).enabled = NO;
}
like image 158
James Paolantonio Avatar answered Dec 25 '22 22:12

James Paolantonio


Of course you can. Just use the property enabled of the UIButton. When the user presses it, set enabled to NO: [myButton setEnabled:NO];, and set YES when you need enable it again later.

like image 39
Natan R. Avatar answered Dec 25 '22 23:12

Natan R.