Reputation: 3470
I am trying to count when the there is a left swipe action. However, with the code I have so far the result is always 1.
Any Ideas Why?
- (void)handleSwipes:(UISwipeGestureRecognizer *)sender
{
int countLeft = 0;
if (sender.direction == UISwipeGestureRecognizerDirectionLeft)
{
countLeft += 1;
imagesequence = @"2.png";
[_MainBackground setImage:[ UIImage imageNamed: imagesequence]];
NSLog(@"LEFT = %d", countLeft);
}
if (sender.direction == UISwipeGestureRecognizerDirectionRight)
{
NSLog(@"RIGHT");
imagesequence = @"3.png";
[_MainBackground setImage:[ UIImage imageNamed: imagesequence]];
}
}
Upvotes: 0
Views: 76
Reputation: 68400
The problem is that int countLeft = 0;
is defined inside the method scope so every time it runs, countLeft
is defined and initialized to 0
, you'll need to promote that to a wider scope to keep the latest execution value (move definition outside method).
Upvotes: 1