2012-12-31 67 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考虑接受答案,如果这有助于你 –