我想在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