Obj-C - пользовательский вид аннотации карты, вид из XIB - PullRequest
0 голосов
/ 24 сентября 2018

Я пытаюсь отобразить пользовательский вид / XIB, когда отмечена аннотация на моем MapView.Тем не менее, я нашел разные ответы на этот вопрос для swift - но ни одного для цели C.

В настоящее время я могу отображать пользовательские аннотации со следующим кодом:

ViewController.m

-(void)viewDidLoad {


    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[@"node_title"];
            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 *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{



            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
    {

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

        }

    }

Тем не менее, если я хочу, чтобы созданный мной пользовательский XIB отображался в качестве выноски при каждом прикосновении к аннотации, где / как я должен вызывать это?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...