我想在MKAnnotation中添加更多详细信息,例如位置标题,说明,日期,位置名称。所以这将是四条线所需要的。但是我发现只有2个参数可以传递给标题和副标题的MKAnnotation。我如何在地图上添加更多细节? Plz帮助我..提前感谢。如何在iOS中的MKAnnotation中添加更多详细信息
回答
看看创建自定义MKAnnotationView
对象......它基本上是一个为地图注释量身定做的UIView
。在那个对象中,你可以拥有4个自定义标签。
在你MKMapViewDelegate
类,需要实现viewForAnnotation
方法:
- (CustomMapAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
CustomMapAnnotationView *annotationView = nil;
// determine the type of annotation, and produce the correct type of annotation view for it.
CustomMapAnnotation* myAnnotation = (CustomMapAnnotation *)annotation;
NSString* identifier = @"CustomMapAnnotation";
CustomMapAnnotationView *newAnnotationView = (CustomMapAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if(nil == newAnnotationView) {
newAnnotationView = [[[CustomMapAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease];
}
annotationView = newAnnotationView;
[annotationView setEnabled:YES];
[annotationView setCanShowCallout:YES];
return annotationView;
}
这将显示在以往任何时候,如果你想一步步的教程,check out this video你有一个注释...您的自定义视图。
希望这有助于
编辑
我其实只是找到了一个新Maps example在苹果开发站点...有你需要去通过所有的源代码。他们也使用自定义MKAnnotationView
叫WeatherAnnotationView
谢谢你的答案。我是否可以将细节添加到想要的格式的默认气泡中,如使用换行符?我尝试通过将UIlabel添加到MKPinAnnotationView的rightCalloutAccessoryView。但它不提供nice.thanks提前 – 2010-02-26 22:27:38
我不会尝试这样做你试图做到这一点...苹果已设置注释,以便他们可以扩展与MKAnnotationView类。试图以你正在做的方式覆盖正确的CalloutAccessoryView并不是一个好的方法来做到这一点......你正在与框架战斗,它给你带来了奇怪的结果。如果您想要自定义注释,最好的方式就是我描述的方式。 – 2010-02-27 16:15:18
查看我的新编辑了解更多信息 – 2010-02-28 06:01:39
- 1. 如何更多详细信息添加到JPA验证异常
- 2. 在Ios中的主详细信息页
- 3. SugarCRM在详细信息视图中添加其他详细信息图标
- 4. 如何在mvc中添加详细信息
- 5. 如何在WPF中动态添加详细信息行?
- 6. 如何在wso2中添加外部配置详细信息
- 7. 如何在JSF数据表中添加行详细信息?
- 8. 如何在MessageBox中添加详细信息?
- 9. 如何在ArrayList中添加客户详细信息?
- 10. Crystal Reports详细信息详细信息
- 11. Android主详细信息详细信息
- 12. CakePHP的主/详细信息添加
- 13. 有关DWR的更多详细信息?
- 14. 添加更多详细信息powershell命令输出
- 15. 在静态HTML页面中显示WordPress帖子 - 添加更多详细信息
- 16. 添加详细信息链接结构
- 17. 主详细界面中详细信息的多重视图
- 18. 环内循环(更多详细信息)
- 19. 购物车更多详细信息
- 20. 如何在iOS中获取来电详细信息
- 21. 如何在iOs中获取Google Place详细信息值
- 22. 向企业库中的异常处理添加更多详细信息
- 23. 更新详细信息ci
- 24. ActiveReports多列详细信息
- 25. 如何在Angular中获得更详细的错误信息?
- 26. 如何使用googleVis包在R中的gvisGeoMap中详细了解更多信息?
- 27. 如果我无法明确定义详细信息,如何添加到主详细信息的linq2sql实体集?
- 28. 如何删除添加到“添加可信站点?”所需的详细信息?
- 29. 在Codeigniter日志中添加详细信息
- 30. OrangeHrm在PIM个人详细信息中添加字段
我试图通过添加到副标题的细节..但它显示在一行..我如何能显示多行细节 – 2010-02-26 13:59:53