button event change

Discussion in 'iOS Programming' started by dutch85, Jul 7, 2009.

  1. dutch85 macrumors newbie

    Joined:
    Jul 7, 2009
    #1
    hello i am creating a drum machine app, right now i have 12 buttons with events that each play a different sound. any ways i would like to allow my users to select between 3 different sounds for each button allowing them to create their own drum sets. such as using a touch drag exit that will switch the event of a button to a new one with a new sound.

    sorry if a made this sound confusing i couldnt think of a better way to explain it

    thanx
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
  3. dutch85 thread starter macrumors newbie

    Joined:
    Jul 7, 2009
    #3
    how can i change the event of a button through a touch drag exit method

    for example you have button1, its event on load is to play sound1 with a touch up in it method

    what i want to do but don't know how, is change the event of that button to a new one using a touch drag exit method so when a touch up in it method is now executed it will play a different sound

    sorry again im having a hard time explaining what im trying to do
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    OK, I think there are two parts to this.

    You can change the target/action for a button easily. You can use the addTarget:action:forControlEvents: and removeTarget:action:forControlEvents: methods to change the target/action for a button.

    The other part is: what UI do you use to allow the user to indicate that they are changing this? There is of course nothing built-in that does this. Do you have some idea of how you want the user to do this? I can image going to a detail view that has pickers for these things or other controls that let the user change the action. I can image some kind of control that changes the mode of the view from the normal 'execute the action' to 'choose an action' and in the choose an action mode touching a button changes its action, rather than executes the action.

    What do you have in mind for the UI?

    I guess from your saying that you want to change the action/target by a touch you want something like my second method described above. You could have something like this:

    You have an Edit/Done button. Changing to Edit mode allows configuring the buttons.
    In Edit mode when you tap on a button it changes its title.
    Say you have three sounds, sound1, sound2, sound3.
    In non-edit mode a button's title is sound2. When the user taps the button it plays the sound.
    In edit mode when the user taps the button the title changes to sound3. Maybe it also plays the sound. If the user taps the button again it displays sound1, and so on.
    When the user taps the Edit/Done button to exit edit mode then the buttons return to only playing their sound.

    Make any sense?
     
  5. dutch85 thread starter macrumors newbie

    Joined:
    Jul 7, 2009
    #5
    im sorry but i have no clue how to implement and use addTarget:action:forControlEvents:
    in my code. this is my first time coding in c i usually code in basic. below is a link to download the source to my project im working on. i would like to keep the same ui and execute the addTarget:action:forControlEvents: through a touch drag exit

    thanx for your help

    s222660058.onlinehome.us/sound2.zip
     
  6. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    Dutch,

    What you describe is a complicated but I think do-able UI. If you are a complete beginner then it's probably beyond you at this point.

    I recommend that you get one of the iPhone books and work through it doing the examples. You should be able to work through the book in a matter of days to weeks depending on how much time you spend. Come back to this problem after that.
     
  7. dutch85 thread starter macrumors newbie

    Joined:
    Jul 7, 2009
    #7
    wow who would of thought it would be that complicated something similar can be achieved in basic with a simple if then else. anyways thanx for your help
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    I'm curious. What would the condition of this 'if' be? You can even describe it using pseudo-code.
     
  9. dutch85 thread starter macrumors newbie

    Joined:
    Jul 7, 2009
    #9
    i use another ui object in vb, a radio button

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If RadioButton1.Checked = True Then
    Label1.Text = "hello world"
    Else
    Label1.Text = "hello person"
    End If


    End Sub
    End Class
     
  10. ChOas macrumors regular

    Joined:
    Nov 24, 2006
    Location:
    The Netherlands
    #10
    ?!?!?!?!?

    But that is something totally different from what you were asking before, and, if this can be achieved so easily in VB using a radio button, why not use a radio button for this in Cocoa ?
     
  11. dutch85 thread starter macrumors newbie

    Joined:
    Jul 7, 2009
    #11
    there doesn't seem to be a radio button object for cocoa touch at least it does not show one in my object library menu. the next best thing would be the segmented control. it would be ideal to use a list menu but again it does not show a list menu in the object library menu. i was also thinking some kind of context menu on a 2 finger touch would be ideal. but again i don't see a context menu in my object library menu
     
  12. ChOas macrumors regular

    Joined:
    Nov 24, 2006
    Location:
    The Netherlands
    #12
    For list menu you can use a picker object.

    Segmented control would be another way to go, I guess...

    something like :

    Code:
            UISegmentedControl *soundControl = [ [ UISegmentedControl alloc ] initWithFrame: CGRectMake(16, 16, 128, 32) ];
           [ soundControl insertSegmentWithTitle: @"Sounds1" atIndex: 0 animated: NO ];
           [ soundControl insertSegmentWithTitle: @"Sounds2" atIndex: 1 animated: NO ];
           [ soundControl insertSegmentWithTitle: @"Sounds3" atIndex: 2 animated: NO ];
           soundControl.selectedSegmentIndex = 0;
    
           [soundControl addTarget:self action:@selector(optionChanged:) forControlEvents:UIControlEventValueChanged];
    
    
    Now, in optionChanged: you could change the actions of the buttons, or in the action method of the button you could check the currently selected index of the UISegmentedControl and base your action on that (like your vb example) (This here below assumes you have access to your soundControl control) :

    Code:
    - (void) buttonClicked:(id) sender {
     
     if (soundControl.selectedSegmentIndex == 0) {
      NSLog(@"Sounds 1 selected");
     };
     if (soundControl.selectedSegmentIndex == 1) {
      NSLog(@"Sounds 2 selected");
     };
     if (soundControl.selectedSegmentIndex == 2) {
      NSLog(@"Sounds 3 selected");
     };
    
    };
    
    I think... or something close to that (I probably messed up some stuff in there, but it's an idea).
     
  13. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #13
    The closest thing in Cocoa Touch to a radio button is a UISwitch.

    But back to the OP, if you want each button to invoke one of three different sounds, I would also suggest using a segmented control (with three options).
     

Share This Page