2012-12-31 64 views
1

嗨我有一個地圖視圖頁面在我的應用程序中,我顯示200 +標記。客觀c mapkit點擊按鈕註釋

我啓動這些目前與

MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:currentobjectarray.title andCoordinate:location]; 

這些產生一個文本標籤被點擊標記時。我如何將一個按鈕添加到註釋視圖,以便當它被點擊時,我可以導航到選定標記的「更多信息」頁面。它的按鈕部分我不確定。

任何幫助非常讚賞

+0

您需要使用自定義的註解視圖。 – Lefteris

回答

2

你需要創建一個UIButton並將其分配給您的MKAnnotationView的rightCalloutAccessoryView財產。

mapView:viewForAnnotation:方法中,如果您正在返回自定義MKAnnotationView實例,請插入此代碼以創建按鈕並將其與操作關聯。

我假設你的MKAnnotationView實例被稱爲annotationView,並且你要調用的方法是presentMoreInfo

UIButton * disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
[disclosureButton addTarget:self 
        action:@selector(presentMoreInfo) 
      forControlEvents:UIControlEventTouchUpInside]; 
annotationView.rightCalloutAccessoryView = disclosureButton; 

presentMoreInfo方法可以是這樣的

- (void)presentMoreInfo { 
    DetailsViewController * detailsVC = [DetailsViewController new]; 

    //configure your view controller 
    //... 

    [self.navigationController pushViewController:detailsVC animated:YES]; 
} 
+0

@ user1096447考慮接受答案,如果這有助於你 –