Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Xino

macrumors member
Original poster
Sep 5, 2008
36
0
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:
Code:
- (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

macrumors newbie
Oct 11, 2007
17
0
Netherlands
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

macrumors member
Original poster
Sep 5, 2008
36
0
Thanks, since i'm coding my UI and not using IB I had to edit the following line:
Code:
[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

macrumors newbie
Nov 2, 2008
8
0
Hey have you any solution for that whitout IB?? I have a very similar code:
[streamVideoBtn addTarget:self action:mad:selector(takePicture) forControlEvents:UIControlEventTouchUpInside];

Thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.