Reputation: 1025
I'm detecting a long tap to put a pin on the map and its working, I add a pinId variable that i increment evry time i drop a poin to check that only two pins are dropped in the same map but here something is not working fine i guess because i can only put one pin on the map!
Here is the code:
-(void)handleLongPressGesture:(UIGestureRecognizer*)sender {
if (sender.state == UIGestureRecognizerStateEnded)
{
[self.mapView removeGestureRecognizer:sender];
}else{
if (pinId < 3) {
CGPoint point = [sender locationInView:self.mapView];
CLLocationCoordinate2D locCoord = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];
MapAppAnnotation* annotation = [[MapAppAnnotation alloc]initWithCoordinate:locCoord andID:pinId];
pinId++;
[mapView addAnnotation:annotation];
[annotation release];
}}
}
- (void)update{
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];
[self.mapView addGestureRecognizer:longPressGesture];
[longPressGesture release];
}
- (void)viewDidLoad {
[super viewDidLoad];
//...
pinId = 1;
self.update;
}
Upvotes: 0
Views: 221
Reputation: 4686
At a guess; it's because removeGestureRecognizer
is being called after the first long press. Does it work if you remove that call?
Upvotes: 1