I am showing an alert on UILongPressGestureRecognizer, the issue I am facing is that every time I have to click it three times to dismiss the alert while the alert should be dis
It fires multiple times to indicate the different states of the gesture (began, changed, ended, etc). So in the handler method, check the state property of the gesture recognizer to avoid doing the action at each state of the gesture.
In your case:
- (void)tableCellPressed:(UILongPressGestureRecognizer *)recognizer
{
VehicleListCell* cell = (VehicleListCell *)[recognizer view];
cellValueForLongPress = cell.licPlate.text;
NSLog(@"cell value: %@", cellValueForLongPress);
if (gestureRecognizer.state == UIGestureRecognizerStateBegan)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil] ;
[alert addButtonWithTitle:@"Add to Favourites"];
[alert addButtonWithTitle:@"Take to Map"];
[alert show];
}
}