У меня есть аннотации в моем обзоре карты (self.friendsMapView), которые должны отображать выноску при нажатии. Каждая аннотация отображает заголовок и описание (тело). По какой-то причине, что бы я ни пытался, мое уточнение не будет отображаться, если моя аннотация будет нажата. Я что-то упустил?

Немного предыстории: у меня раньше было два mapView внутри одного ViewController (и у меня нормально работали выноски). Однако после того, как я решил удалить одно отображение карты (self.neighboursMapView) и его код, мои выноски для self.friendsMapView, похоже, перестали работать.

< Сильный > ViewController.m

    - (void)viewDidLoad {
        [super viewDidLoad];


         friendsMapView.showsUserLocation = YES;
        [friendsMapView setMapType:MKMapTypeStandard];
        [friendsMapView setZoomEnabled:YES];
        [friendsMapView setScrollEnabled:YES];

        NSMutableDictionary *viewParamsFriend = [NSMutableDictionary new];
        [viewParamsFriend setValue:@"accepted_friends" forKey:@"view_name"];
        [DIOSView viewGet:viewParamsFriend success:^(AFHTTPRequestOperation *operation, id responseObject) {


            self.friendData = [responseObject mutableCopy];

            int index = 0;

            for (NSMutableDictionary *multiplelocationsFriend in self.friendData) {


                NSString *location = multiplelocationsFriend[@"address2"];
                NSString *userNames = multiplelocationsFriend[@"first name"];
                NSString *userBio = multiplelocationsFriend[@"body"];


                CLGeocoder *geocoderFriend = [[CLGeocoder alloc] init];
                [geocoderFriend geocodeAddressString:location
                             completionHandler:^(NSArray* placemarks, NSError* error){
                                 if (placemarks && placemarks.count > 0) {
                                     CLPlacemark *topResult = [placemarks objectAtIndex:0];
                                     MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];

                                     MKCoordinateRegion region = self.friendsMapView.region;

                                     region.span.longitudeDelta /= 150.0;
                                     region.span.latitudeDelta /= 150.0;


                                     PointAnnotation *point = [[PointAnnotation alloc] init];
                                     point.coordinate = placemark.coordinate;
                                     point.title = userNames;
                                     point.subtitle = userBio;
                                     point.index = index;  // Store index here.

                                     [self.friendsMapView addAnnotation:point];
                                 }
                             }
                 ];

                index = index + 1;

            }

        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"Failure: %@", [error localizedDescription]);
        }];


    }

-(MKAnnotationView*)mapView:(MKMapView*)friendsMapView viewForAnnotation:(id<MKAnnotation>)annotation {

    if([annotation isKindOfClass:[meetupAnn class]]) {
        static NSString *identifier = @"currentLocation";
        SVPulsingAnnotationView *pulsingView = (SVPulsingAnnotationView *)[self.friendsMapView dequeueReusableAnnotationViewWithIdentifier:identifier];

        if(pulsingView == nil) {
            pulsingView = [[SVPulsingAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
            pulsingView.annotationColor = [UIColor colorWithRed:0 green:0.678431 blue:0 alpha:1];
            pulsingView.canShowCallout = YES;
        }

        return pulsingView;
    }


    MKAnnotationView *view = nil;
    if (annotation != self.friendsMapView.userLocation) {

        NSLog(@"Friend Map Showing");

        view = [self.friendsMapView dequeueReusableAnnotationViewWithIdentifier:@"AnnotationIdentifier"];
        if (!view) {

            static NSString* AnnotationIdentifier = @"AnnotationIdentifier";

            MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
                                                                            reuseIdentifier:AnnotationIdentifier];
            annotationView.canShowCallout = YES;
            annotationView.image = [UIImage imageNamed:@"mapann3.png"];
            UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

            annotationView.rightCalloutAccessoryView = rightButton;
            annotationView.canShowCallout = YES;
            annotationView.draggable = YES;


            return annotationView;



        }
    }

    return view;

}

    - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
    {

       if (mapView == self.friendsMapView) {

            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];

        }

    }
-1
Brittany 19 Сен 2018 в 06:29

2 ответа

Лучший ответ

Попробуйте метод viewForAnnotation со следующей конфигурацией.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{


    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

    if ([annotation isKindOfClass:[MKPointAnnotation class]])
    {

        MKAnnotationView *pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"];
        if (!pinView)
        {

            pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];

            pinView.canShowCallout = YES;
            pinView.image = [UIImage imageNamed:@"annotation"];
            pinView.calloutOffset = CGPointMake(0, 0);


            UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"annotation"]];
            pinView.leftCalloutAccessoryView = iconView;


        } else {
            pinView.annotation = annotation;
        }
        return pinView;
    }
    return nil;

}
0
TheTravloper 19 Сен 2018 в 04:48

Попробуйте метод viewForAnnotation со следующей конфигурацией.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{


    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

    if ([annotation isKindOfClass:[MKPointAnnotation class]])
    {

        MKAnnotationView *pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"];
        if (!pinView)
        {

            pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];

            pinView.image = [UIImage imageNamed:@"annotation"];

        } else {
            pinView.annotation = annotation;
        }
        pinView.canShowCallout = YES;
        pinView.calloutOffset = CGPointMake(0, 0);

        UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"annotation"]];
        pinView.leftCalloutAccessoryView = iconView;

        return pinView;
    }
    return nil;

}
0
Kosuke Ogawa 19 Сен 2018 в 06:20