-2

我将如何从方法中调用此viewDidLoad方法?

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

我被困在语法上:[self mapview:.....];

4

3 回答 3

1

你不打电话mapView:didSelectAnnotationView。在它的委托上运行的MKMapView调用。检查这个:如何触发 mapView:didSelectAnnotationView ?

 [self.delegate mapView:someMapView didSelectAnnotationView:someAnnotationView];
于 2013-06-13T12:43:59.287 回答
1

你不知道 - 这是MKMapView当用户触摸MKAnnotationView. MKMapView如果要在加载时自动选择注释,请使用它的selectAnnotation:animated方法。

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

当您调用时selectAnnotation:animated:,您的注释会弹出,然后,如果用户触摸它,mapView:didSelectAnnotation:就会调用您的注释。通常,您永远不会调用MKMapViewDelegate(或任何 *Delegate 中的方法)。系统会在适当的时候为您呼叫。

PSviewDidLoad不接受争论。

于 2013-06-13T12:49:28.483 回答
0

将其粘贴到 xcode 中:

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

您需要将引用传递给 themapView和 theannotationView才能正常工作。

于 2013-06-13T12:44:08.150 回答