У меня есть два разных класса аннотаций на моем mapView.При нажатии на каждый тип аннотации появляется другая выноска.При касании первого типа выноски аннотации мой пользователь выводится на другой экран.Тем не менее, когда второй тип коснулся, я хочу, чтобы отображалось предупреждение.
Как я могу выполнить это?Я просто не уверен, куда я должен поместить TapGesture для calloutTappedThree.Пока смотрите код ниже:
MapViewController.m
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
if([annotation isKindOfClass:[meetupAnn class]]) {
static NSString *identifier = @"currentLocation";
MKAnnotationView *pulsingView = (MKAnnotationView *)[self.friendsMapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if(pulsingView == nil) {
pulsingView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
pulsingView.canShowCallout = YES;
pulsingView.image = [UIImage imageNamed:@"meetupbeacon.png"];
UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"meetupbeacon.png"]];
pulsingView.leftCalloutAccessoryView = iconView;
}
return pulsingView;
}
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if ([annotation isKindOfClass:[MKPointAnnotation class]])
{
MKAnnotationView *pinView = (MKAnnotationView*)[self.friendsMapView dequeueReusableAnnotationViewWithIdentifier:@"AnnotationIdentifier"];
if (!pinView)
{
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"AnnotationIdentifier"];
pinView.image = [UIImage imageNamed:@"mapann3.png"];
} else {
pinView.annotation = annotation;
}
pinView.canShowCallout = YES;
pinView.calloutOffset = CGPointMake(0, 0);
UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mapann3.png"]];
pinView.leftCalloutAccessoryView = iconView;
return pinView;
}
return nil;
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(calloutTappedTwo:)];
[view addGestureRecognizer:tapGesture2];
}
-(void)calloutTappedTwo:(UITapGestureRecognizer *) sender
{
NSLog(@"CALL OUT TWO TAPPED");
MKAnnotationView *view = (MKAnnotationView*)sender.view;
id <MKAnnotation> annotation = [view annotation];
if ([annotation isKindOfClass:[MKPointAnnotation class]])
{
PointAnnotation *selectedPoint = (PointAnnotation *) view.annotation;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
OtherUserViewController *yourViewController = (OtherUserViewController *)[storyboard instantiateViewControllerWithIdentifier:@"OtherUserViewController"];
NSMutableDictionary *dictionary = self.friendData[selectedPoint.index];
yourViewController.frienduserData = dictionary;
[self.navigationController pushViewController:yourViewController animated:YES];
}
}
-(void)calloutTappedThree:(UITapGestureRecognizer *) sender
{
NSLog(@"Callout Three was tapped");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"RSVP for Meet-Up?"
message:@"Test Alert!"
delegate:self
cancelButtonTitle:@"Join"
otherButtonTitles:@"Maybe Next Time...",nil];
[alert show];
}