我可以在 iphone 应用程序项目中显示地图,并将图钉放置在我想要的位置,但我希望在视图加载时显示标题和副标题。这是我正在使用的代码。我以为放入
[mapView selectAnnotation:注释动画:是];
会起作用,但事实并非如此。有谁知道如何做到这一点?
Thanks
CLLocationCoordinate2D 坐标 = {纬度:32.02008,经度:-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];
在将其添加到地图之前调用 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的委托属性,否则该方法将不会被调用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)