tags:

views:

291

answers:

1

Hi there, I have a simple routine to count everytime the user clicks a button.

However the integer (numberOfClicks) increments by four each time. Could the event be happening more than once for each user tap?

(btw the action method below is connected to the 'touch up inside' action)

- (IBAction)myButtonClicked
{
   numberOfClicks+=1;
   NSString *clicks = [NSString stringWithFormat:@"number of clicks = %d", numberOfClicks];
   myLabel.text = clicks;
}

Many Thanks, Chris

+1  A: 

If you add in a call like NSLog(clicks), and you run the code, do you get the log message 4 times?

Are other buttons connected to this IBAction?

Have you connected this IBAction to more than one outlet of your single button -- i.e. Touch Up Inside, Touch Up Outside, Touch Drag Inside, Touch Drag Outside, etc.?

Shaggy Frog
Hi there, I've check with the IB and it is only connected to the one button. The NSLog trace returns an increase of 4 each time, so still puzzled by this one.
CJR
From your code, `numberOfClicks` lives outside this function, maybe as a member variable. Is any other code modifying `numberOfClicks`? Where is it initialized?
Shaggy Frog