Detect when my UIButton is pressed?

Discussion in 'iOS Programming' started by MythicFrost, Dec 19, 2009.

  1. MythicFrost macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #1
    OK, I've managed to create a menu I'm happy with. I want it so when I click Play it calls a function, I'm wondering though, how do I do that?
    I've found [bPlay touchesBegan] but I'm not sure what to do with the parameters that it wants.
    Code:
    [bPlay touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event];
    Can anyone help? Thanks.

    EDIT: figured it out with Google :)
    Code for anyone that needs it:
    Code:
    [bPlay addTarget:self action:@selector(bPlay_TouchDown) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
    
    - (void)bPlay_TouchDown {
    }
    
    The example code had @selector(bPlay_TouchDown:) but it made my app crash, I think it's because my function doesn't have any arguments.
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    Typically you want a button to send its action message on touch up inside, not on touch down.

    If this is new to you then you should get one of the books on iPhone development.
     
  3. MythicFrost thread starter macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #3
    I would like to get a book, but for now I'll keep doing what I'm doing.
    I'll change it to Touch Up Inside then, thanks :)
     

Share This Page