Getting a title to display when loading a map with mkmap

I can get a map for display and a pin to drop where I want in my iphone application project, but I want the title and subtitles to appear when the view loads. Here is the code I'm using. I thought [mapView selectAnnotation: annotated animated: YES];

will work, but it is not. Does anyone know how to do this?

thank

CLLocationCoordinate2D coord = {latitude: 32.02008, longitude: -108.479707};

    [self.view addSubview:mapView];


MapController *annotation = [[MapController alloc]  initWithCoordinate:coord];
annotation.currentPoint = [NSNumber numberWithInt:1];
annotation.mTitle = @"MyTitle";
annotation.mSubTitle = @"My Address";
[mapView selectAnnotation:annotation animated:YES];
[mapView addAnnotation:annotation];
[annotation release];
+1
source share
1 answer

selectAnnotation , , , AddAnnotation , .

didAddAnnotationViews, , :

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    id<MKAnnotation> myAnnotation = [mapView.annotations objectAtIndex:0];
    [mapView selectAnnotation:myAnnotation animated:YES];
}

, mapView. ivar.

, mapView .

+3

Source: https://habr.com/ru/post/1775894/


All Articles