PDA

View Full Version : Disable UIButton after clicking?




Xino
Sep 25, 2008, 04:17 AM
I've developed an iPhone application with some UIButtons. The problem is that when I hold down one of the buttons, the method assigned to the button is being called multiple times but since one of the actions is for deleting some files, the application tries to delete the file multiple times which is causing the application to crash because the file is deleted succesfully the first time the action is being called.

I've tried the following:

- (IBAction)actionButton {
[button1 setEnabled:NO];
// Some actions
[button1 setEnabled:YES];
}

in the hope the button will be deactivated when the action is already being executed but this don't work...

Hope you guys can help me out :)



danielpunt
Sep 25, 2008, 04:26 AM
You can set the action in IB to 'touch up inside'.
Then the action is triggered when the finger is pulled up from the button, so your method is called just one time.

Xino
Sep 25, 2008, 09:47 AM
Thanks, since i'm coding my UI and not using IB I had to edit the following line:

[streamVideoBtn addTarget:self action:@selector(takePicture) forControlEvents:UIControlEventTouchUpInside];


I was already wondering wherefor forControlEvents was, besides that, I've never had this problem with buttons generated with IB.

You helped me out with this one, great :)

powwowath
Jan 9, 2009, 11:21 AM
Hey have you any solution for that whitout IB?? I have a very similar code:
[streamVideoBtn addTarget:self action:@selector(takePicture) forControlEvents:UIControlEventTouchUpInside];

Thanks