Disable UIButton after clicking?

Discussion in 'iOS Programming' started by Xino, Sep 25, 2008.

  1. Xino macrumors member

    Sep 5, 2008
    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 :)
  2. danielpunt macrumors newbie

    Oct 11, 2007
    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.
  3. Xino thread starter macrumors member

    Sep 5, 2008
    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 :)
  4. powwowath macrumors newbie

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


Share This Page