method call using two separate btns pushed?

Discussion in 'iOS Programming' started by jjgraz, Oct 2, 2009.

  1. jjgraz macrumors regular

    jjgraz

    Joined:
    Feb 13, 2009
    #1
    Can I do this?
    call a method by selecting two different buttons at same time?
    Have two separate buttons:

    Button 1: when selected calls 'method A'
    Button 2: when selected calls 'method B'

    the tricky one ----> Buttons 1 & 2: selected at same time calls 'method C'

    Any ideas of what to look up or any hints would be greatly appreciated.
    Thank you.
     
  2. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
  3. jjgraz thread starter macrumors regular

    jjgraz

    Joined:
    Feb 13, 2009
    #3
    there is a code for a button double tap, single tap, all the interface touch ups ,in, out ....ect.....

    There must be a way to write if button 1 and button 2 are selected....do this. Right?
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Don't think so. You can't really have two first responders, now can you?
     
  5. FarSeide macrumors 6502a

    FarSeide

    Joined:
    Feb 17, 2008
    Location:
    Earth Lane
    #5
    your last option wont be possible since the First Responder will only respond to one object at a time.
     
  6. jjgraz thread starter macrumors regular

    jjgraz

    Joined:
    Feb 13, 2009
    #6
    So any clever programmer idea of out thinking. I have a game controller...sort of like the first Generation Nintendo controller with a couple buttons and a pad.....I need to allow different actions with combination of buttons....... Any ideas? Thank you very much.
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    I'd suggest having one control (perhaps an invisible one that sits over top the visible ones) that captures all touches. Then use touchesBegan:, determine where the touches were detected, map them onto your buttons and handle appropriately.
     
  8. jjgraz thread starter macrumors regular

    jjgraz

    Joined:
    Feb 13, 2009
    #8
    Thank you for the suggestion dejo. I will certainly look into this as a way to handle it.
     
  9. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #9
    I think you can do this with buttons. A button can respond if another button is already tapped. I have a toolbar in my app. If I tap on one button it highlights. If I hold down my finger and tap on another button it highlights too. The action of the second button isn't sent though. Only the action of the first button is sent.

    The point is that the touchdown of your two buttons will be called.

    You can see this in the UICatalog app also. Go to the buttons screen and touch one button and hold and then touch a second button. You'll see that both buttons highlight independently.

    You need to set up a state machine that performs whatever action is appropriate based on the states of the two buttons. In theory you could change the target/action of the second button when the first button goes down but I would prefer just to use a little logic to determine the state of the two buttons and do the appropriate action.
     

Share This Page