Вопрос

How would I call this method from the viewDidLoad method?

- (void)mapView:(MKMapView *)mapview didSelectAnnotationView:(MKAnnotationView *)view {
       // code
  }

I'm stuck on the syntax: [self mapview:.....];

Это было полезно?

Решение

You don't - that's a call back you get from an MKMapView when a user touches an MKAnnotationView. If you want to automatically select your annotation when your MKMapView is loaded, use its selectAnnotation:animated method.

-(void)viewDidLoad {
   MKMapView *mapView = // whatever
   MKAnnotation *annotation = // whatever
   [mapView selectAnnotation:annotation animated:YES]; // could be no, in viewDidLoad it won't necessarily be visible
}

When you call selectAnnotation:animated:, your annotation will pop up, then, if the user touches it, your mapView:didSelectAnnotation: will be called. As a rule, you will never call the methods in MKMapViewDelegate (or any *Delegate for that matter). The system will call them for you at the appropriate time.

P.S. viewDidLoad doesn't take an argument.

Другие советы

You don't call mapView:didSelectAnnotationView. The MKMapView calls that function on it's delegate. Check this : how to fire mapView:didSelectAnnotationView ?

 [self.delegate mapView:someMapView didSelectAnnotationView:someAnnotationView];

Paste this into xcode:

[self mapView:<#MKMapView instance#> didSelectAnnotationView:<#MKAnnotationView instance#>];

You will need to pass the references to the mapView and the annotationView for this to work.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top