touchesForView question

Discussion in 'iOS Programming' started by uaecasher, Dec 13, 2009.

  1. macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #1
    I'm trying to record the number of taps made on a button and depending on number of taps a user would get deferent results, I'm having problem with the 1st part, here is my code:

    Code:
    
    - (void)touchesBegan:(NSSet *)touches touchesForView:(button *)view {
    	NSUInteger numTaps = [[touches anyObject] tapCount];
    	
    	myTextFeild.text = [NSString stringWithFormat:@"%i", numTaps];
    	
    }
    
    
    I get:

    error: expected ')' before 'button'

    button is an IBOutlet for UIButton.
     
  2. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    This is the correct prototype

    Code:
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
     
  3. thread starter macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #3
    but I want it to detect only touches made to a button, how to do that?

    Thanks
     
  4. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    UIControl, of which UIButton is one, works at a bit higher level than touches. It will send its action message when it is tapped.

    I would not subclass UIButton for this. I'd just put all the logic in the view controller. Set it up so it receives the action message for touch up inside from the button(s). Save the time and then compare the previous time to the current time when you get the touch up inside. This will allow you to determine a tap count.
     
  5. thread starter macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #5
    I'm not sure how to this
     
  6. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    1) What is your type button (as in (button *) view). Making up types will never work.

    2) As noted above substituting methods you wished existed for ones that actually do exist will never work.

    3) Learn to read the documentation. There is an excellent document on event handling that would lead you to the touchesForView: method of UIEvent. The ability to use, read and understand the documentation is a core skill that must be developed.
     
  7. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #7
    I'm not sure how to this

    UIButtons and other controls work by sending actions to a target when they are touched. I recommend that you read about this in the UIControl docs and UIButton docs and the event handling docs. Set up an action method in your view controller that is messaged on touch up inside from the button. Once you have that working it's a simple matter of logic to keep count of the touches.
     

Share This Page