我将如何从方法中调用此viewDidLoad
方法?
- (void)mapView:(MKMapView *)mapview didSelectAnnotationView:(MKAnnotationView *)view {
// code
}
我被困在语法上:[self mapview:.....];
我将如何从方法中调用此viewDidLoad
方法?
- (void)mapView:(MKMapView *)mapview didSelectAnnotationView:(MKAnnotationView *)view {
// code
}
我被困在语法上:[self mapview:.....];
你不打电话mapView:didSelectAnnotationView
。在它的委托上运行的MKMapView
调用。检查这个:如何触发 mapView:didSelectAnnotationView ?
[self.delegate mapView:someMapView didSelectAnnotationView:someAnnotationView];
你不知道 - 这是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
不接受争论。
将其粘贴到 xcode 中:
[self mapView:<#MKMapView instance#> didSelectAnnotationView:<#MKAnnotationView instance#>];
您需要将引用传递给 themapView
和 theannotationView
才能正常工作。