Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

uaecasher

macrumors 65816
Original poster
Jan 29, 2009
1,289
0
Stillwater, OK
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.
 
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.
 
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.

I'm not sure how to this
 
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.